ASP.NET Core using two models in one form

I use Tupleto transfer two models inside the view, for example the code below.

@model Tuple<AdvanceSearchModel, List<SearchUserModel>>
<form role="search" method="post" action="/Public/AdvanceSearch">
            <div class="form-group">
                <label>Name</label>
                <input name="FullNames" type="text" class="form-control" value=""/>
            </div>
            <div class="form-group">
                <label>Product</label>
                <input name="Products" type="text" class="form-control" value="" />
            </div>
            <div class="form-group">
                <label>Location:</label>
                <input name="Location" type="text" class="form-control" value="" />
            </div>
            <div class="form-group">
                <label>State</label>
                <input name="States" type="text" class="form-control" value="" />
            </div>
            <div class="form-group">
                <label>Country</label>
                <input name="Countries" type="text" class="form-control" value=""/>
            </div>
        </form>

All attributes nameinside the input are relevant AdvanceSearchModel. How to use a helper tag, for example, asp-forwhen transferring multiple models to views that contain one or more forms? Also, how to save the form values ​​after submitting the form in the above script?

+4
source share
1 answer

As you can see in the source code of InputTagHelper

, name, (lambda) html-: asp-for.

name, SearchUserModel[0].Location

:

  • SearchUserModel - , ,
  • [0] -
  • Location iten SearchUserModel instance

  • InputTagHelper ( prefex ).
  • !
  • , SearchUserModel + (, int, , : usermodel[1])
  • .

@model SearchUserModel
<input asp-for="Location" my-prefix="ListItem[@Model.Id]" class="form-control" />

  • HTML-, SearchUserModel.
  • ajax- json . ( 3 , )
  • javascript.
  • On submit , json json ajax.

? , .

, 1 , , , .

html :

+1

Source: https://habr.com/ru/post/1669831/


All Articles