在我的布局页面中,我想显示一个登录框,或者有关登录人员的详细信息。
<div>
@if (Request.IsAuthenticated)
{
@Html.ViewBag.UserDisplay
@Html.ActionLink("[Logout]", "LogoutUser", "User")
}
else
{
@Html.Partial("_Login")
}
<hr />
@RenderBody()
</div>
我的登录部分视图:
@model BasicFinanceUI.Models.LoginModel
@using (Html.BeginForm("LoginUser", "User"))
{
@Html.ValidationSummary()
<p>
Username: @Html.TextBoxFor(x => x.Username)
Password: @Html.TextBoxFor(x => x.Password)
Remember Me: @Html.DropDownListFor(x => x.RememberMe, new[]
{
new SelectListItem() { Text = "Yes", Value = "true"},
new SelectListItem() {Text = "No", Value = "false"}
}, "Select")
<input type="submit" value="Login" />
@Html.ActionLink("[Register]", "Register", "User")
</p>
}
当我加载屏幕并登录时,它可以正常工作。
但是,当我点击“注册”时,它会加载注册屏幕。登录框仍然在布局中可见。
显示我的注册屏幕:
@model BasicFinanceUI.Models.RegisterationModel
@{
ViewBag.Title = "Register";
Layout = "~/Views/Shared/SiteLayout.cshtml";
}
<h2>Register</h2>
@using (Html.BeginForm("Register", "User"))
{
<p>@Html.ValidationSummary()</p>
<p>Username: @Html.TextBoxFor(x => x.Username)</p>
<p>Password: @Html.PasswordFor(x => x.Password1)</p>
<p>Retype Password: @Html.PasswordFor(x => x.Password2)</p>
<p>Firstname: @Html.TextBoxFor(x => x.Firstname)</p>
<p>Surname: @Html.TextBoxFor(x => x.Surname)</p>
<p>Email: @Html.TextBoxFor(x => x.Email)</p>
<p><input type="submit" value="Register"/></p>
}
当我点击“注册”按钮时,出现问题。
我收到错误:
传递到字典中的模型项是类型的 'BasicFinanceUI.Models.RegisterationModel',但这个字典 需要“BasicFinanceUI.Models.LoginModel”类型的模型项。
似乎因为屏幕上有两种形式,它们混在一起。我做错了什么?