我很好奇在一个回复到包含部分View的表单中使用多个强类型部分的方法是否是正确的MVC处理方法.为简洁起见,主视图与以下模型绑定,其中包含其他几个属性和数据注释:
public class AccountSetup : ViewModelBase
{
public bool TermsAccepted { get; set; }
public UserLogin UserLogin { get; set; }
public SecurityQuestions SecurityQuestions { get; set; }
}
public class UserLogin
{
public string LoginId { get; set; }
public string Password { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
主Register.cshtml视图的标记并不完全在下面,但这是部分在下面使用的方式:
@model Models.Account.AccountSetup
. . . <pretty markup> . . .
@using (Html.BeginForm("Register", "Account", FormMethod.Post))
{
. . . <other fields and pretty markup> . . .
@Html.Partial("_LoginAccount", Model.UserLogin)
@Html.Partial("_SecurityQuestions", Model.SecurityQuestions)
<input …Run Code Online (Sandbox Code Playgroud)