Multiple models in a view

前端 未结 12 1844
太阳男子
太阳男子 2020-11-21 23:07

I want to have 2 models in one view. The page contains both LoginViewModel and RegisterViewModel.

e.g.

pub         


        
12条回答
  •  暖寄归人
    2020-11-21 23:22

    Do I need to make another view which holds these 2 views?

    Answer:No

    Isn't there another way such as (without the BigViewModel):

    Yes, you can use Tuple (brings magic in view having multiple model).

    Code:

     @model Tuple
    
    
        @using (Html.BeginForm("Login", "Auth", FormMethod.Post))
        {
         @Html.TextBoxFor(tuple=> tuple.Item.Name)
         @Html.TextBoxFor(tuple=> tuple.Item.Email)
         @Html.PasswordFor(tuple=> tuple.Item.Password)
        }
    
    
        @using (Html.BeginForm("Login", "Auth", FormMethod.Post))
         {
          @Html.TextBoxFor(tuple=> tuple.Item1.Email)
          @Html.PasswordFor(tuple=> tuple.Item1.Password)
         }
    

提交回复
热议问题