LINQ dont want display in ASP.NET MVC

Go To StackoverFlow.com

0

I want to display all records from table of current autorized user in my ASP.NET-MVC 3 + SQL Server 2008 app. But I have some problems:

this code with LINQ-request working good:

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

but this code not work:

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

and this code is working good

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

What I do wrong, please help me.

2012-04-05 16:11
by user


1

You probably want to run your where criteria against the table you're querying, instead of against the argument from the method, i.e.:

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

2012-04-05 16:15
by Kevin Stricker
Oh no it was epic fail! very grateful to You, thanx : - user 2012-04-05 16:30


0

instead of obj.login == u, try

obj.Contains(u)
2012-04-05 16:16
by Diego
it don't work = - user 2012-04-05 16:36
Ads