0

我想在我的 ASP.NET-MVC 3 + SQL Server 2008 应用程序中显示当前自动用户表中的所有记录。但是我有一些问题:

此代码与 LINQ-request 运行良好:

public ActionResult Index(todo obj)
        {
           string u = User.Identity.Name; 
           var th = (from tt in _db.todo select tt);
           return View(th);
        } 

但这段代码不起作用:

public ActionResult Index(todo obj)
          {
             string u = User.Identity.Name; 
             var th = (from tt in _db.todo where obj.login == u select tt);
             return View(th);
           }

这段代码运行良好

if (u == obj.login) { ViewBag.res = "ok"; } else { ViewBag.res = "fail"; }

我做错了什么,请帮助我。

4

2 回答 2

1

您可能希望针对您正在查询的表运行您的 where 条件,而不是针对方法中的参数,即:

var th = (from tt in _db.todo where tt.login == u select tt);

于 2012-04-05T16:15:03.743 回答
0

而不是obj.login == u,尝试

obj.Contains(u)
于 2012-04-05T16:16:09.697 回答