This project is read-only.


Mar 4, 2016 at 11:38 PM
On sort, I noticed the page with form data was attempting to GET vs POST.

As a workaround, I inserted the following jQuery snippet at the bottom of the cshtml file:
@section Scripts {
<script type="text/javascript">
      $(".grid-header-title").click(function (e) {
          if ($("a")) {
              // It was the anchor element that was clicked -- meaning, its sortable

              // '/Search' should be replaced with your form action
              $(document.forms[0]).attr("action", '/Search' + $("href")); 
Aug 2, 2016 at 8:59 PM
Hi could you please provide me similar solution for filter and paging ?
Aug 8, 2016 at 5:03 PM
I'll add as much as possible...

grind code in cshtml page (.net mvc);
@Html.Grid(Model.resultTable).Columns(columns =>
      columns.Add(foo => foo.transaction_date).Titled("Date").SetWidth(110).Sortable(true);
      columns.Add(foo => foo.tender_total).Titled("Total").SetWidth(110).Sortable(true);
      columns.Add(foo => foo.C3rdParty).Titled("3rd Party?").SetWidth(50).Sortable(true);
The above creates a grid with the with sortable columns, and limiting to 10 results per page.

Not sure if that's what you meant on filtering/paging.
Aug 9, 2016 at 8:33 PM
Hi, first of all thanks for the reply.

No that is not what I meant.

On sort, I noticed the page with form data was attempting to GET vs POST. " For this your solution worked fine.

But when I filter or click on paging it still goes to the GET method instead of POST which will lose all the data I have stored in my model.

To be clear I have 2 methods GET and POST. GET is used to get the data initially from the database. POST is to post user changes.
In my view I have a very large model with too many EditorFor controls and a MVC Grid. So when user filters any column or click on paging in the grid, the control goes to the GET method and all the data in my model is lost. :( The above given solution worked totally fine for Sort problem. Now could you give me solution for filter and paging.

" $(".grid-header-title").click(function (e) {" How to identify the click method for filter and paging ???
Aug 9, 2016 at 9:07 PM
Edited Aug 9, 2016 at 9:11 PM
OK, my workaround for this was to save things in Session variables on the server.

When paging, I do an jquery post to the server to store the variable. Then I modified the GET to restore from session if available.
                url: '@Url.Action("StorePageVars")',
                type: 'POST',
                data: { data: jsonDataHere },
                success: function (result) {
And on the server side, the post to store:
        public ActionResult StorePageVars(string data) // -->this is a json object you can store and de-serialize if needed.
            Session["dataToSave"] = data;
            return Content("OK");
And finally the GET on paging/initial page load:
            if (Session["searchModel"] != null)
                //do restore stuff
                model = new SearchViewModel();
                ViewBag.stuff= "''";
            return View(model);
You'll have to hook into the "click" routine on the paging, or just store session data on actions in your web page click events (what I do when user checks checkboxes, etc.).

The other thing you need to make sure to do is re-set the Session to NULL on a fresh page load (or in my case, a search).
Aug 9, 2016 at 9:14 PM
Oh... I was trying to avoid session. But if no other way may be have to use session :(. Thanks for your help :) :)