【问题标题】:Cannot perform runtime binding on a null reference error in partial view无法对部分视图中的空引用错误执行运行时绑定
【发布时间】:2013-12-06 09:03:39
【问题描述】:
Cannot perform runtime binding on a null reference error

我在局部视图中收到此错误。

loginUserExists = Membership.ValidateUser(UserNameLogin, PasswordUserLogin);
if (loginUserExists==false)
{
    return;
}
FormsAuthentication.SetAuthCookie(UserNameLogin, true);

这是我产生错误的部分观点。

@*This is where the error happens*@
**@if (!Page.User.Identity.IsAuthenticated)**
{
    <li><a href="@Url.Action("LoginForm", "Home")">Login</a></li>
    <li><a href="@Url.Action("RegisterForm", "Home")">Register</a></li>
}
else
{

    <li><a href="@Url.Action("LoginForm", "Home")">Logout</a></li>
    if (Model.FirstName != null)
    {
        <li><label id="labUserName">@Model.FirstName</label></li>
    }
}

局部视图嵌套在布局页面中。

也许了解我为什么会得到这个以及如何克服它?

问候

【问题讨论】:

    标签: asp.net-mvc-3 asp.net-membership


    【解决方案1】:

    改用Request.IsAuthenticated

    @if (!Request.IsAuthenticated)
    {
        // ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多