I'm experimenting a bit with several grids in asp.net mvc. Microsoft has a grid too know in the prerelease of mvc 3 so I thought I'll try that one out.
The basic functionality is quite easy to implement but when it comes to sorting, I'm having some problems. The grid handles its sorting by the url. In the url you have the sort column and the sort direction in the following way: ?sortdir=ASC&sort=ABONNEMENT
Now you would expect that after you've done the sorting on the certain column, the sortdir querystring on that column would change to ?sortdir=DESC but it doesn't. It stays ?sortdir=ASC . Does anybody knows if this is a bug or a feature, and how to solve this?
Another very annoying thing: if I click on a sort link, an httpget request is done. Because of this I loose my model. Because there is the possibility on the page to filter the grid (search functionality), I want to preserve this in the model. It would be a much easier & cleaner solution in my opinion to put this data in the model state, than to store it in the session state. Is it possible to change the behaviour of the sorting header links so a http post is executed?
Any ideas or thoughts on this? Tnx for the help.
greetz, Koen
The code of the view is the following:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<table>
<tr>
<td>
<h1 class="normal">List of subscription</h1>
</td>
<td>
</td>
</tr>
</table>
<% using (Html.BeginForm("List", "Subscription", FormMethod.Post)) { %>
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td>
Search By
</td>
<td>
<%: Html.DropDownListFor(m => m.SearchByColumn, Ogone.FrontEnd.Web.Controllers.SubscriptionController.SubscriptionSearchList) %>
</td>
<td>
<%: Html.TextBoxFor(m => m.SearchByText) %>
</td>
<td>
<input name="button" type="submit" value="Search" />
</td>
</tr>
</table>
<div>
<%
var grid = new System.Web.Helpers.WebGrid(Model.SubscriptionList,
columnNames: new List<string>(){"Title"},
canPage:false);
%>
<%= grid.GetHtml(columns: grid.Columns(
grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.ID })),
grid.Column("ID"),
grid.Column("ISP"),
grid.Column("ABONNEMENT"),
grid.Column("MODE"),
grid.Column("SETUPFEE"),
grid.Column("MONTHLYFEE"))
) %>
</div>