我很難從我的數據庫中獲取任何信息。 我覺得我在正確的軌道上,但總是出現此錯誤:從數據庫中登錄的用戶信息列表
Object reference not set to an instance of an object.
在我的控制器類我有這個方法:
[HttpPost]
public ActionResult Index(Oblig1.Models.User user)
{
if (Bruker_i_DB(user) != null)
{
Session["User"] = User.ToString();
ViewBag.LoggedIn = true;
return View();
}
else
{
Session["User"] = null;
ViewBag.LoggedIn = false;
return View();
}
}
,並在.cshtml文件I已經得到了這個:
@model Oblig1.Models.User
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
</head>
<body>
<div>
<title>LoggedInSite</title>
<p>@Model.Email</p>
</div>
</body>
</html>
這對任何人都有意義嗎? 幾天我開始得到相當沮喪的後...
對我來說沒有意義,但你可能想'返回查看(用戶);' – 2014-10-08 09:53:53
你不是通過模型對象來從行動中查看 – 2014-10-08 09:55:50
請完全添加您的視圖.... – 2014-10-08 10:28:15