asp.net mvc - MvcPaging using Ajax -
i want use mvcpaging in partialview. have search page , need paginate results. far, first page results appears - when trying go page 2 in console 500 error , nothing happens.
here 2 actions controller:
public partialviewresult searchresults(string lat, string lng, double? dist) { if (request.isajaxrequest()) { string address = request["address"]; string latitude = lat; string longitude = lng; geocoordinate coord = new geocoordinate(double.parse(latitude, cultureinfo.invariantculture), double.parse(longitude, cultureinfo.invariantculture)); iqueryable<restaurants> near = (from r in _db.restaurants select r); results = new list<restaurants>(); foreach (restaurants restaurant in near) { double latbd = (double)restaurant.latitude; double lngdb = (double)restaurant.longitude; if (new geocoordinate(latbd, lngdb).getdistanceto(coord) <= dist * 1000) { results.add(restaurant); } } return partialview("_searchresult", results.topagedlist(0, 2)); } return partialview("search"); } public actionresult paginationajax(int? page) { int currentpageindex = page.hasvalue ? page.value - 1 : 0; return partialview("_searchresult", results.topagedlist(currentpageindex, 2)); }
and partial view:
@model ipagedlist<restaurants> @using mvcpaging foreach (var item in model) { <blockquote> <h3><a href="details?id=@item.id" target="_blank">@item.name</a></h3> </blockquote> } <div class="pager"> @html.pager(model.pagesize, model.pagenumber, model.totalitemcount, new ajaxoptions { updatetargetid = "searchresults" }).options(o => o.action("paginationajax")) </div>
does has idea doing wrong? thanks!
edit: error
get http://localhost/takeaseat/restaurants/paginationajax?page=2&x-requested-with=xmlhttprequest&_=1431698681795 500 (internal server error) jquery.ajaxtransport.send @ jquery-2.1.3.js:8625 jquery.extend.ajax @ jquery-2.1.3.js:8161 asyncrequest @ jquery.unobtrusive-ajax.js:128 (anonymous function) @ jquery.unobtrusive-ajax.js:138 jquery.event.dispatch @ jquery-2.1.3.js:4430 jquery.event.add.elemdata.handle @ jquery-2.1.3.js:4116
Comments
Post a Comment