How do I update list after delete row by jquery ajax in asp.net mvc? -
my problem when deleted row , after delete row it'll hidden in list , when use ie , f5 refresh page row still display. chorme , firefox work fine.
listview :
@model ienumerable<pg.admin.models.timesheetheaders.timesheetheaderviewmodel> @{ viewbag.title = ""; layout = "~/views/shared/_layout.cshtml"; } @scripts.render("~/scripts/jquery.unobtrusive-ajax.js") <div id="unobtrusive"> @html.partial("_timesheetlist", model) </div>
_listtimesheet (partial view)
@model pagedlist.ipagedlist<pg.admin.models.timesheetheaders.timesheetheaderviewmodel> @using pagedlist.mvc; <table class="table table-striped"> <tbody> <tr> <th> @html.displaynamefor(model => model.first().date) </th> <th> @html.displaynamefor(model => model.first().pgid) </th> <th> @html.displaynamefor(model => model.first().outletid) </th> <th></th> </tr> @foreach (var group in model) { <tr> <td>@html.displayfor(model => group.date)</td> <td>@html.displayfor(model => group.pgid)</td> <td>@html.displayfor(model => group.outletid)</td> <td> @html.actionlink("delete", "deletetimesheetconfirmed", new { id = group.id }, new { @id = group.id, @class = "delete-timesheet" }) </td> </tr> } </tbody> </table> <div class="datatable-paging"> <div class="row"> <div class="col-xs-6"> <div class="paging-info"> page @(model.pagecount < model.pagenumber ? 0 : model.pagenumber) of @model.pagecount </div> </div> <div class="col-xs-6"> <div class="paging-content"> @html.pagedlistpager(model, page => url.action("grouplisttimesheet", new { page, key = viewbag.currentfilterkey, currentfilter = viewbag.currentfilter }), pagedlistrenderoptions.enableunobtrusiveajaxreplacing(new ajaxoptions() { httpmethod = "get", updatetargetid = "unobtrusive" })) </div> </div> </div> </div> <script type="text/javascript"> $('.delete-timesheet').on("click", function (e) { var flag = confirm('delete ?'); if (flag) { e.preventdefault(); var id = e.target.id; $.ajax({ url: '@url.action("deletetimesheetconfirmed", "timesheet")', type: 'post', data: { id: id }, datatype: "json", cache: false, success: function () { $("#" + id).closest('tr').remove(); }, error: function () { alert('error!'); } }); } return false; }); </script>
controller:
public actionresult grouplisttimesheet(string key, string searchname, string currentfilter, int? page) { var grouptimesheet = _timesheetservice.grouptimesheetbytimesheetheader().tolistviewmodel(); if (searchname != null) { page = 1; } else { searchname = currentfilter; } viewbag.currentfilter = searchname; viewbag.currentfilterkey = key; if (!string.isnullorempty(searchname) && key == "pgcode") { grouptimesheet = grouptimesheet.where(m => m.pgid.contains(searchname)).tolist(); } if (!string.isnullorempty(searchname) && key == "quancode") { grouptimesheet = grouptimesheet.where(m => m.outletid.contains(searchname)).tolist(); } if (!string.isnullorempty(searchname) && key == "date") { grouptimesheet = grouptimesheet.where(m => convert.tostring(m.date).contains(searchname)).tolist(); } int pagesize = 15; int pagenumber = (page ?? 1); if (request.isajaxrequest()) { return (actionresult)partialview("_timesheetlist", grouptimesheet.topagedlist(pagenumber, pagesize)); } else { return view(grouptimesheet.topagedlist(pagenumber, pagesize)); } } [httppost] public actionresult deletetimesheetconfirmed(int64 id) { var timesheetheader = _timesheetservice.gettimesheetheaderbyid(id); if (timesheetheader == null) return redirecttoaction("index"); _timesheetservice.deletetimesheet(timesheetheader); return json(true, jsonrequestbehavior.allowget); }
timesheetservice:
public iqueryable<timesheetheader> grouptimesheetbytimesheetheader() { var grouptimesheet = tsh in _timesheetheaderrepository .includetable( m => m.timesheetdetails, m => m.pgprofile, m => m.quan, m => m.worktype).orderbydescending(m => m.date) select tsh; return grouptimesheet.asqueryable(); }
sounds partial view caching.
for partial view add [outputcache(duration=1)]
action (for reason 0 not allowed on partial view).
for full view there several options
[outputcache(nostore = true, duration = 0, varybyparam = "none")]
or just
[outputcache(duration=0)]
Comments
Post a Comment