我使用登录表单创建了一个网站。首先,我创建登录表单只是为了在帐户/登录下进行测试。然后一些需要更改所有页面应该显示登录。所以我创建了一个部分并在_Layout.cshtml下面调用,
<div id="logindisplay">
@{ Html.RenderPartial("_LogOnPartial"); }
</div>
_LogOnPartial.cshtml:
@model HOP2013.Models.LogOnModel
@{
ViewBag.Title = "Log On";
}
@if(Request.IsAuthenticated) {
<text>Welcome <b>@Context.User.Identity.Name</b>!
[ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text>
}
else {
@: @Html.ActionLink("Log On", "LogOn", "Account")
}
@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")
@using (Html.BeginForm()) {
<fieldset>
<legend>Account Information</legend>
<div id="user" class="user">
<div class="editor-label">
@Html.LabelFor(m => m.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.UserName, new { @title = "UserName" })
@Html.ValidationMessageFor(m => m.UserName)
</div>
</div>
<div id="password" class="password">
<div class="editor-label">
@Html.LabelFor(m => m.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.Password, new { @title = "UserName" })
@Html.ValidationMessageFor(m => m.Password)
</div>
<div class="editor-label">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
</div>
<p>
<input type="submit" class="login" value="Log On" />
</p>
<p>New @Html.ActionLink("Register", "SignUp", "Account")Here</p>
</fieldset>
}
但我无法登录。如果我使用单独的页面(LogOn.cshtml)登录意味着它正在成功登录。我不知道为什么会这样..任何人都可以澄清我。