0

I have a WebGrid sort that is not doing anything upon clicking the headers.

The WebGrid is contained within a Partial View that looks like this -

@model MyModel

var grid = new WebGrid(Model.MyList, defaultSort: "MyField", canSort: true, ajaxUpdateContainerId: "MyContainer", canPage: false);  
<div id="MyContainer">
          @grid.GetHtml(
            columns: grid.Columns(
                grid.Column("col1", "Col1", format: @<text>@item.field1</text>),
                grid.Column("col2", "Col2", format: @<text>@item.field2</text>),
                grid.Column("col3", "Col3", format: @<text>@item.field3</text>)

           )
          )
 </div>

In the controller -

    [HttpGet]
    public ActionResult MyController()
    {
        MyModel m = new MyModel()

        m = (MyModel)Session["MyModel"];

        return PartialView("MyView", dr);
    }

I was wondering if it has something to do with the fact that I am pulling the model from a Session variable? If not is there something else I may be doing wrong?

If nothing looks wrong, any information as to how WebGrid sort works to help me trouble shoot would be greatly appreciated.

Thanks!

A Bogus
  • 3,852
  • 11
  • 39
  • 58
  • Maybe it's not the sort, but how you chose to get updates. You have ajaxUpdateContainerId specified, but where is that container element that will get replaced? – LouD Apr 26 '13 at 20:43
  • Thanks for the interest Loud. I do have the grid surrounded by a div with the ajaxUpdateContainerId. I updated my question to reflect this. – A Bogus Apr 29 '13 at 13:56

1 Answers1

0

Maybe is too late but I've seen it today... You must receive the next params in the controller function that loads your containing grid (I've done it with VB):

Optional ByVal page As Integer? = Nothing, _
Optional ByVal sort As String = Nothing, _
Optional ByVal sortDir As String = Nothing, _

Then you must pass this parameters to the function that makes the search on your database and in your stored procedure use the sort and sortDir params. The page param page is to be able to paginate. The sort param will keep the field to order and the sortDir if it's ASC or DESC.