我正在使用代码这些代码行但发生错误 [英] i'm using code these line of code but error occur

查看:58
本文介绍了我正在使用代码这些代码行但发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 @ if(Session [firstname]!= null&& Session [lastname]!= null)
{
< span class = name > @Session [firstname] @Session [lastname] < / span >
}
其他
{
@ Url.Action(登录,登录)
}







错误:

对象引用未设置为对象的实例。

解决方案

尝试将此预先挂起到会话:

 @ System.Web.HttpContext.Current.Session 





如果不这样做,会话对象本身可能只是完全无效,所以它甚至无法检查您的条件。在检查任何存储的会话对象是否为空之前,您应首先检查会话对象本身。



会话!=  


@if (Session["firstname"] != null && Session["lastname"] != null)
{
   <span class="name">@Session["firstname"] @Session["lastname"]</span>
}
else
{
   @Url.Action("Login", "Login")
}




error:

Object reference not set to an instance of an object.

解决方案

Try pre-pending this to session:

@System.Web.HttpContext.Current.Session



If that doesn't do it, the session object itself may just be entirely null, so it can't even check your conditions in the first place. You should first check the session object itself before checking to see if any stored session objects are null.

Session!=null


这篇关于我正在使用代码这些代码行但发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆