This is a migrated thread and some comments may be shown as answers.

[Solved] Page and Sort grid after server binding from form post data

0 Answers 34 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
tafs7
Top achievements
Rank 1
tafs7 asked on 11 Jul 2012, 06:01 PM
I have an MVC grid inside a Partial View (MVC3) that represents search results.  In my main view, I have a form with search criteria, which a user will input and submit.

On the action that receives the search criteria from the AJAX form post (using a strongly typed model), I retrieve data from a backend service and return it as a model to the Partial View.  This provides the grid with an IEnumerable and the AJAX Form helper does the work of updating a DIV with the content of the Partial View - which now has a rendered grid.

The problem I have is that if now, I try to page or sort the grid, it tries to refresh the main view which won't work because the data is not fetched when the view loads, but rather when the user posts the form within the view.

Here's what my Partial View grid code looks like (Razor):
@(Html.Telerik().Grid(Model)
    .Name("SearchResultsGrid")
    .Sortable()
    .Filterable()
    .Pageable(p => p.PageSize(10))
    .Scrollable(s => s.Height(250))
    .KeyboardNavigation(k => k.Enabled(true))
    .Columns(c =>
    {
        c.Bound(o => o.AccountNumber);
        c.Bound(o => o.FirstName).Width(150);
        c.Bound(o => o.LastName).Width(150);
        c.Bound(o => o.Email).Width(200);
        c.Bound(o => o.PhoneNumber).Width(130);
        c.Bound(o => o.City).Width(150);
        c.Bound(o => o.StateProvince).Width(60).Title("State");
        c.Bound(o => o.PostalCode).Width(100).Title("Zip");
        c.Bound(o => o.TaxId).Width(100);
    })
)

Can someone point me to how I can implement the Paging/Sorting and pass it the model data that was used to render the Partial View from the form post?

thanks!
Tags
Grid
Asked by
tafs7
Top achievements
Rank 1
Share this question
or