开发者

MVC3 WebGrid is holding onto it's paged data after a new grid is created via post!

I'm having an issue with WebGrid paging; but first, here's some controller pseudo code:

public ActionResult Date()
{
  var data = getLINQ();
  return View(data);
}

[HttpPost]
public ActionResult Date(string start, string finish)
{
   var data - getLINQ(start, finish);
   return View(data);
}

..and some view code:

@model IEnumerable<ModelClass>

@{
   ViewBag.Title = "Date";
   Layout = "~/Views/Shared/_Layout.cshtml";
   var grid = new WebGrid(source: Model, rowsPerPage: 25);
}


@using (Html.BeginForm())
{
<fieldset>
    <span>From date: <input type="text" id="start" name="start" data-val="true" value="@ViewBag.start" /></span> 
    <span>To date: <input type="text" id="finish" name="finish" data-val="true" value="@ViewBag.finish" /></span>
    <input type="submit" value="Update" />
</fieldset>
}

<div>
@grid.GetHtml(tableStyle: "table", caption: "Claims Between " + @ViewBag.start + " and " + @ViewBag.finish, htmlAttributes: new { cellspacing = "0", cellpadding = "0", id = "_grid" }, 
                      开发者_开发知识库  columns: grid.Columns(
                        grid.Column("ID", "ID"),
                        grid.Column("DateReceived", "Date Received"),
                        grid.Column("Client", "Client"),
                        grid.Column("ReferenceNumber", "Reference Number"),
                        grid.Column("PatientLastName", "Patient Last Name"),
                        grid.Column("PatientFirstName", "Patient First Name"),
                        grid.Column("ClaimType", "Type"),
                        grid.Column("BilledCharges", "Billed Charges", item => String.Format("{0:C}", item.BilledCharges ?? 0)),
                        grid.Column("ReimbursementAgent", "Reimbursement Agent")))
</div>

So, as you can decipher, the idea here is if a user GETS /Date, they are presented with a default set of data. If the user POSTS start and finish dates to /Date, the user is presented with that subset of data.

This is working great atm, save for one snare: If you GET the /Date, you have a paged resultset (page numbers under the grid), if you then POST and get new data, then click on any of the page numbers, the grid reloads with the original resultset and with the original paging!

Is there some way to reset that? Any help is appreciated!


Ok - its not exactly what you want - but rather than fixing webgrid code, My recommendation when dealing with the WebGrid is to drop it in use of a far better control (imho)- the Telerik MVC grid. Its free, open source, and very easy to use. You can setup ajax paging with about two lines of code. Download it at:

http://telerikaspnetmvc.codeplex.com/

Demo: http://demos.telerik.com/aspnet-mvc/grid/

blog entry: http://msmvps.com/blogs/bmains/archive/2010/01/04/using-the-telerik-mvc-grid.aspx

Lots of info on the net - but the demo should show you its quite easy. There's no comparison as far as I'm concerned - and like I said - free and open source.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜