In charge of filtering data in MVC


I have a MVC web application and it contains a GRID with KENDOUI framework where it shows all the data in the "Patient" table, I wish < strong> filter the data to be displayed in the table according to the identified user which is already implemented with winform, I did the search but indicate that it can be done from the .cshtml view, others that it is better from the controller, which would be the recommended way or as stipulated by the MVC pattern in

asked by Miko 02.03.2016 в 04:01

1 answer


The filter must be implemented in the action the controller , you can not filter in cshtml if you expect to challenge a json as an answer.

public ActionResult tblpaciente_Read(){

    IQueryable<tblpaciente> tblpacientes = db.tblpacientes.Where(p=> p.Usuario == User.Identity.Name);

    //resto codigo

    return Json(result)

I'm not sure how to implement the security of the site, maybe the User.Identity should change it to adapt to your implementation, but it would be in the action where you would implement the filter on the property of the entity.

answered by 02.03.2016 в 04:13