Restrict Kendo Grid to Current Route Id -
i'm trying include kendo ui asp.net mvc grid on edit page of mvc application , restrict grid return values current route id. i've been researching ways this, can't find that's need, or i'm new @ connect dots.
my ideas far either apply filter datasource or send parameter controller , have restrict datasourceresult.
for datasource filter in view, can this:
.filter(filters => { filters.add(d => d.companyid).isequalto(2); })
but can't figure out how replace hardcoded 2 value from, say, @viewcontext.routedata.values["id"], or something.
passing parameter controller, can following:
public actionresult divisions_read([datasourcerequest]datasourcerequest request, int id) { using (var db = new appcontext()) { iqueryable<division> divisions = db.divisions; datasourceresult result = divisions.todatasourceresult(request, division => new divisionviewmodel { divisionid = division.divisionid, companyid = division.companyid, countryid = division.countryid, divisionname = division.divisionname }); return json(result); } }
but have no idea how use id add "where companyid = id" statement result.
any ideas on best way be? missing obvious?
thanks!
eta: passing parameter controller through read action, suggested mmillican , other places in research, , changing
datasourceresult result = divisions.todatasourceresult(request, division => new divisionviewmodel
to
datasourceresult result = divisions.where(c => c.companyid == companyid).todatasourceresult(request, division => new divisionviewmodel
did trick. bit in controller looking for, couldn't seem find anywhere.
assuming have model page looks this:
public class myviewmodel { public int id { get; set; } // assuming id want filter // .. other vm properties }
you can in grid data binding
.datasource(ds => ds .ajax() .model(mdl => mdl.id(x => x.id)) .read("divisions_read", "divisions", new { id = model.id }) )
in controller, set model's id
property whatever id in route.
Comments
Post a Comment