我无法使用mvc 5身份在一个视图中显示登录和注册表单 我添加了这个模型。
public class Logreg
{
public RegisterViewModel reg { get; set; }
public LoginViewModel log { get; set; }
}
比我加入此控制器
public ActionResult Logreg()
{
var model = new Logreg();
model.log = new LoginViewModel();
model.reg = new RegisterViewModel();
return View(model);
}
所以我也添加了视图。
@using WebApplication2.Models.Logreg
@{
ViewBag.Title = "Logreg";
}
<h2>Login Register</h2>
@Html.Partial("_Reg")
@Html.Partial("_Log")
所以最后一个我添加了_log.cshtml和_reg.cshtml作为登录和注册视图的副本。 _log
@using WebApplication2.Models.LoginViewModel
@{
Layout = null;
}
@using (Html.BeginForm("Login", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
@Html.PasswordFor(m => m.Password, new { @class = "form-control" })
<input type="submit" value="Log in" class="btn btn-default" />
}
_REG
@model WebApplication2.Models.RegisterViewModel
@{
Layout = null;
}
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
@Html.PasswordFor(m => m.Password, new { @class = "form-control" })
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
<input type="submit" class="btn btn-default" value="Register" />
}
因此只能通过调用logreg.cshtml显示登录表单。 如何解决这个问题呢。请帮忙。