I have a WebGrid in a cshtml view and i'm using the ajaxUpdateContainerId parameter to page/sort it using AJAX. But, each time i click on a link to page/sort the WebGrid, the href is changing and the querystring add a "__swhg" parameter.
Please refer the attached image
And the querystring just keep growing like this each time I click on the sort/pager, the "__swhg" parameter keep growing because "href" attributes in the WebGrid are adding this to the simple "?sort=&sortdir=" or "?page=".!
This parameter represents an unique timestamp and is added to each url on purpose. Since the AJAX requests are using GET verb, those requests might be cached by the browser. This means that when the user clicks on the links, your server might never be reached. The parameter ensures that the responses are not cached, because each time you get an unique url. Currently this is hardcoded in the WebGrid and there's no way to disable it.
Of course if for some reason you want to shoot yourself in the foot and remove this parameter one possibility is to subscribe to a custom AJAX callback:
var grid = new WebGrid(
Model,
ajaxUpdateContainerId: "grid",
ajaxUpdateCallback: "callback"
);
in which you could replace all links and remove the __swhg
parameter:
function callback() {
$('a[data-swhglnk="true"]').attr('href', function () {
return this.href.replace(/&__swhg=[0-9]{13}/, '');
});
}