我有问题,在我的MVC 3项目中,登录视图没有显示虽然我检查了我的html文件并且有html元素但它们没有显示。请看一下,并给我一些建议来解决这个问题。
以下是我的观点:
<!DOCTYPE html>
<html>
<head>
<title>LogOn</title>
<link href="@Url.Content("~/Content/Admin/css/reset.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/Admin/css/CMSS.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Content/Admin/scripts/jquery-1.6.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/Admin/scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
</head>
<body>
<div class="error-container"></div>
<div id="login-wrapper">
<div class="background">
<h3>
<span class="title">CMS</span></h3>
<div class="form">
<p class="seperation"></p>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<table>
<col class="col-title" />
<col class="col-value" />
<tr>
<td>@Html.LabelFor(model => model.UserName)</td>
<td>
@Html.EditorFor(model => model.UserName)
@Html.ValidationMessageFor(model => model.UserName)
</td>
</tr>
<tr>
<td class="login-title">@Html.LabelFor(model => model.Password)</td>
<td>
@Html.EditorFor(model => model.Password)
@Html.ValidationMessageFor(model => model.Password)
</td>
</tr>
<!--<tr>
<td colspan="2">
<asp:CheckBox ID="cbxRemember" runat="server" Text="Ghi nhớ" />
</td>
</tr>-->
<tr>
<td></td>
<td>
<input type="submit" value="Log On" />
</td>
</tr>
</table>
}
</div>
@if (Model.EnablePasswordReset)
{
<p class="forgot-links">
<a id="forgot-pass">@Html.ActionLink("Forgot Password?", "ForgotPassword")</a></p>
}
</div>
<p class="shadow">
</p>
<p class="copyright">
<span class="copy">© 2011 CMS. All Rights Reserved.</span>
</p>
@{Html.RenderAction("ForgotPassword", "Account");}
</div>
<div class="overlay"></div>
</body>
</html>
这是我的控制器:
[HttpGet]
public virtual ActionResult LogOn()
{
var viewModel = new LogOnViewModel();
return View(viewModel);
}
[HttpPost]
public virtual ActionResult LogOn(LogOnViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
MembershipUser user = membershipService.GetUser(model.UserName);
var role = roleService.GetRolesForUser(user.UserName);
if (authenticationService.LogOn(model.UserName, model.Password, false)) // in CMS do not for remember user for security
{
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
if (IsAdministrator(role))
{
return RedirectToAction("Index", "Dashboard", new { area = "Admin" });
}
return RedirectToAction("Index", "Account");
}
}
else
{
if (user == null)
{
ModelState.AddModelError("", "This account does not exist. Please try again.");
}
else
{
if (!user.IsApproved)
{
ModelState.AddModelError("", "Your account has not been approved yet.");
}
else if (user.IsLockedOut)
{
ModelState.AddModelError("", "Your account is currently locked.");
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
}
}
// If we got this far, something failed, redisplay form
return RedirectToAction("LogOn");
}
我从Firefox获得的结果:
答案 0 :(得分:0)
感谢您的评论,我发现了这个问题。由我的元素引起的设置显示无。我没仔细检查。谢谢了!