Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 LINQ不希望在ASP.NET MVC中显示_Asp.net Mvc 3_Sql Server 2008 - Fatal编程技术网

Asp.net mvc 3 LINQ不希望在ASP.NET MVC中显示

Asp.net mvc 3 LINQ不希望在ASP.NET MVC中显示,asp.net-mvc-3,sql-server-2008,Asp.net Mvc 3,Sql Server 2008,我想在我的ASP.NET-MVC 3+SQL Server 2008应用程序中显示当前自动调整用户表中的所有记录。但我有一些问题: 此代码与LINQ请求工作正常: public ActionResult Index(todo obj) { string u = User.Identity.Name; var th = (from tt in _db.todo select tt); return View(th)

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

此代码与LINQ请求工作正常:

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"; }

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

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


var th=(从_db.todo中的tt开始,其中tt.login==u选择tt)

请尝试使用
obj.login==u
,而不是
obj.login==u

obj.Contains(u)

哦,不,这是史诗般的失败!非常感谢你,thanx:)