2

我有一个问题,在我的 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 得到的结果:

在此处输入图像描述

4

1 回答 1

0

感谢您的评论,我发现了问题。它是由我的元素设置为无显示引起的。我没有仔细检查。再次感谢!

于 2012-12-18T14:28:46.563 回答