0
我想根據簡單的條件返回視圖,但無法這樣做。看起來好像我錯過了一個非常簡單的東西在某個地方,但無法弄清楚。根據if條件返回視圖
我想要做的是根據用戶ID返回不同的意見。
如果下面的代碼是「usercontext.UserId!= 1」,它的工作原理!但它不適用於usercontext.UserId == 1.我在這裏錯過了什麼?
public ActionResult Index()
{
UserProfile usercontext = new UserProfile();
if (usercontext.UserId == 1) {
return View(db.Employees.Where(x => x.DepartmentID == 2).ToList());
}
else {
return View(db.Employees.ToList());
}
}
因爲用戶ID始終爲0 – 2014-09-13 07:26:34
如何?你能解釋我嗎? – sensahin 2014-09-13 07:27:59
,因爲你在上面的行中實例化它。 – paqogomez 2014-09-13 07:30:26