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