I am trying to view the data and check the session parameter but I got error :
Additional information: LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method, and this method cannot be translated into a store expression.
This is the controller code :
public ActionResult Results()
{
var samples = _context.RESULTS.Where(s => s.status==2 && s.custid == (int)Session["HospitalId"]).ToList(); ;
return View(samples);
}
How to solve this error please and check the session parameter value when view the data ?
I changed the code :
int hospitalId = (int)Session["HospitalId"];
var samples = _context.RESULTS.Where(s => s.status == 2 && s.custid == hospitalId).ToList();
but got error :
object reference not set to an instance of an object
I send the hospitalId when click details button like this
@Html.ActionLink("Details","Index","Samples" , new { hospitalId = item.user_id},new {@class = "btn btn-primary" })
This is the controller code INDEX:
public ActionResult Index()
{
int[] exclude = { 13, 14, 15 };
var samples = _context.samples.Where(m => !exclude.Contains(m.id)).ToList();
return View(samples);
}
How can I save the hospitalid value from this link and use it in the second controller ?
int hospitalId = (int)Session["HospitalId"];
var samples = _context.RESULTS.Where(s => s.status == 2 && s.custid == hospitalId).ToList();