视图中的多个模型我想有两个模型在一个视图。该页包含两个LoginViewModel和RegisterViewModel.G.public class LoginViewModel{
public string Email { get; set; }
public string Password { get; set; }}public class RegisterViewModel{
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }}我是否需要制作另一个包含这两个视图模型的ViewModel?public BigViewModel{
public LoginViewModel LoginViewModel{get; set;}
public RegisterViewModel RegisterViewModel {get; set;}}我需要将验证属性提交给视图,这就是我需要ViewModel的原因。没有其他方法,例如(没有BigViewModel): @model ViewModel.RegisterViewModel
@using (Html.BeginForm("Login", "Auth", FormMethod.Post))
{
@Html.TextBoxFor(model => model.Name)
@Html.TextBoxFor(model => model.Email)
@Html.PasswordFor(model => model.Password)
}
@model ViewModel.LoginViewModel
@using (Html.BeginForm("Login", "Auth", FormMethod.Post))
{
@Html.TextBoxFor(model => model.Email)
@Html.PasswordFor(model => model.Password)
}
3 回答
- 3 回答
- 0 关注
- 526 浏览
添加回答
举报
0/150
提交
取消