jquery - Refresh Grid.Mvc after update data -
i have such grid mvc:
@helper customrendering(int id) { @*<button class="btn btn-primary" onclick="location.href='@url.action("acceptrequest", "tablerequest", new { id = id })'"> accept</button>*@ <button class="btn btn-primary" onclick="postaccept(@id)" id="@id"> accept</button> <button class="btn btn-danger" onclick="setwindowid(@id)" id="@id">decline</button> } @html.grid(model).columns(columns => { columns.add(c => c.username).titled("name").filterable(true); columns.add(c => c.datestart).titled("datestart"); columns.add(c => c.dateend).titled("dateend"); columns.add(c => c.approved).titled("approved"); columns.add(o => o.id).encoded(false).sanitized(false) .titled("action") .rendervalueas(o => customrendering(o.id).tohtmlstring()); }).withpaging(10).sortable(true)
and have such js script:
var tempid; function setwindowid(id) { $("#dialog").dialog(); tempid = id; } function postmessage() { var message = $('textarea#commentfordecline').val(); var obj = {}; obj.mes = $('textarea#commentfordecline').val(); obj.mes = message; obj.id = tempid; $.ajax({ type: "post", url: "/tablerequest/declinerequest", data: {'message': obj.mes, 'id': obj.id}, success: function (msg) { } }); $("#dialog").dialog('close'); $('textarea#commentfordecline').val(''); } function postaccept(id){ $.ajax({ type: "post", url: "/tablerequest/acceptrequest", data: {'id': id }, success: function (msg) { } }); }
as can see js functions use buttons, may see on block @helper
. send 2 post ajax call mvc actions. , i've got problem: it's necessary refresh page see updates. there way refresh grid mvc after db update?
public virtual actionresult acceptrequest(int id) { using(var _db = new applicationdbcontext()) { shedule shedule = _db.shedules.singleordefault(x => x.id == id); shedule.isdirectorapproved = true; _db.savechanges(); } return redirecttoaction("index"); } [httppost] public virtual actionresult declinerequest(string message, int id) { using (var _db = new applicationdbcontext()) { shedule shedule = _db.shedules.singleordefault(x => x.id == id); shedule.isdirectorapproved = false; shedule.message = message; _db.savechanges(); } return redirecttoaction(mvc.tablerequest.actionnames.index); }
Comments
Post a Comment