i have this code in my controller
[HttpGet]
public ActionResult Nabipour()
{
string name = "Nabipour";
var username = (from T in _db.tbl_teacher
where T.Page==name
select T.Username);
ViewBag.Nabipour = from N in _db.tbl_Tpage
where N.Username.Equals(username)
select N;
ViewBag.papers = from P in _db.tbl_Tpaper
where P.Username.Equals(username)
select P;
return View();
}
and this is my view for this action:
@{
ViewBag.Title = "Nabipour";
Layout = "~/Views/Shared/_otherpage.cshtml";
}
....
<ul>
@foreach (var paper in ViewBag.papers)
{
<li><a href="~/Content/Paper/@paper.PaperName"></a></li>
}
</ul>
....
so as you see i not checking null in my select code and i tried this code with .FirstOrDefault()
in the select. the error
Cannot compare elements of type 'System.Linq.IQueryable 1 . Only primitive types, enumeration types and entity types are supported
is on @foreach (var paper in ViewBag.papers)
please help me what should i do?
ViewBag
– user3559349username
isIQuerable
, not astring
. You needvar username = (from T in _db.tbl_teacher where T.Page==name select T.Username).FirstOrDefault();
– user3559349