MVC 3 Razor Form Post w/ Multiple Strongly Typed Partial Views Not Binding

后端 未结 2 1333
[愿得一人]
[愿得一人] 2021-02-09 06:43

I\'m curious about whether the approach of using multiple strongly typed partials within a form that posts back to the partial containing View is the right MVC approach to doing

相关标签:
2条回答
  • 2021-02-09 07:01

    This is because your Partial views are strongly typed. Remove the @model declaration in your Partials and access the Model properties like this

    @Html.Partial("_LoginAccount")
    

    and then in your partial

    <div>
         @Html.TextBoxFor(mod => mod.UserLogin.LoginId)
         @Html.PasswordFor(mod => mod.UserLogin.Password)
    </div>
    
    0 讨论(0)
  • 2021-02-09 07:01

    All partials views should be strongly typed with the same view model (AccountSetup in your case) :

    @model Models.Account.AccountSetup
    
    @Html.TextBoxFor(mod => mod.UserLogin.LoginId)
    @Html.PasswordFor(mod => mod.UserLogin.Password)
    

    Then:

    @Html.Partial("_LoginAccount", Model)
    
    0 讨论(0)
提交回复
热议问题