0
當我在我的佈局頁面寫代碼 在剃刀布局中訪問會話變量?
配置文件
@Session [「iname」]。ToString();
我得到這個錯誤
Object reference not set to an instance of an object.
我試圖 @ HttpContext.Current.Session [ 「INAME」]。的ToString() 但不工作
當我在我的佈局頁面寫代碼 在剃刀布局中訪問會話變量?
配置文件
@Session [「iname」]。ToString();
我得到這個錯誤
Object reference not set to an instance of an object.
我試圖 @ HttpContext.Current.Session [ 「INAME」]。的ToString() 但不工作
這意味着,有什麼用會話中的密鑰"iname"
。 Null
檢查這個使用ToString
前:
@if(Session["iname"] != null)
{
Session["iname"].ToString();
}
'@Session [ 「INAME」]'爲空。你有沒有設置它?在任何情況下,我通常都會建議通過視圖模型將數據傳遞到視圖,並讓您的控制器將它從會話中拉出。 –
institute ins =(from I in db.institutes where I.uid == id select I).FirstOrDefault(); iimage im =(from im in db.iimages where Im.uid == id && Im.isLogo == 1 select Im).FirstOrDefault(); Session [「iid」] = ins.Id; Session [「iname」] = ins.Title; Session [「ilogo」] = im.imgpath; – pavan
任何機構可以在佈局中區分訪問會話變量的類型嗎? – pavan