Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3978384
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:02:27+00:00 2026-05-20T05:02:27+00:00

I’m new to MVC so have some conceptual issues. I have a WebGrid that

  • 0

I’m new to MVC so have some conceptual issues. I have a WebGrid that populates with data from a viewmodel, and with that is a DropDownList that the user can select how many records to return (50, 100, etc.), which is also a property on the VM. I have set the DDL’s onchange client side event to fire this.form.submit() and my controller action gets the POST. The trouble is logic for refreshing the view doesn’t fire. The View simply updates the selected value in the DDL.

/* Controller actions */

public ShopsController()
{
    ViewBag.PageList =
    new SelectList(new[] { 10, 15, 25, 50, 100, 1000 }
        .Select(x => new { value = x, text = x }), "value", "text");
}

[HttpGet]
public ActionResult Index()
{
    var model = new ShopsViewModel();
    return View(model);
}
[HttpPost]
public ActionResult Index(int RowsPerPage)
{
    var model = new ShopsViewModel();
    TryUpdateModel(model);
    return View(model);
}

The View uses JSON to update the data in the grid so it can be paged using the technique Malcolm Sheridan blogged about here. I’ve snipped code for brevity.

    <script type="text/javascript">
    $(function () {
        // fire JSON request to initially fill grid
        $.getJSON("/Shops/ShopsPager", null, function (d) {
            $("#grid").append(d.Data);

            $("#DataTable tfoot a").live("click", function (event) {
                event.preventDefault();
                OnPageClick($(this).text() );
            });
            $("#tLinks a").live("click", function (event) {
                event.preventDefault();
                OnPageClick($(this).text() );
            });
        });
    });
</script>
@Html.BeginForm();
    // this is the DDL that when changed, I want the view to refresh using the new value
    <div class="rlinks" style="float:right;">Display&nbsp;
         @Html.DropDownList("RowsPerPage", ViewBag.PageList as SelectList, 
           new{onchange= "this.form.submit();"})&nbsp;Items per page
    </div>
    <div id="grid" class="gridWrapper">
        <!-- the grid get inserted here by the JSON callback
    </div>

So what happens is the page loads and the JSON call fetchs the WebGrid with the number of rows currently specified in Model.RowsPerPage property. Change it from say 25 to 50 the submit() fires and the Index() POST action gets called. The parameter is correct and TryUpdateModel() correctly updates the value of RowsPerPage. The action returns the default view with the updated model, but the View does not refresh, it does not perform the JSON call. Since I’m not really really sure how this routing and AJAX works together this is probably something simple.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:02:28+00:00Added an answer on May 20, 2026 at 5:02 am

    Since you are trying to Postback the page, in which Postback is eliminated in MVC, you are just trying to refresh the page, but what actually refreshes your grid is your $.getJSON call to /Shops/ShopsPager. Instead, don’t postback your page, just call the getJSON again on DDL onchange event.

    Assuming your /Shops/ShopsPager accepts a parameter RowsPerPage like your Index.

    $(document).ready(function(){
        // Fires Initially.
        GetPage(null);
    });
    
    function GetPage(data) {
        var passedData;
        if(data == null)
            passedData = null;
        else {
            passedData = $(data).val();
        }
    
        // Assuming called action accepts RowsPerPage parameter.
        $.getJSON("/Shops/ShopsPager", { "RowsPerPage" : passedData }, function (d) {
            $("#grid").append(d.Data);
    
            $("#DataTable tfoot a").live("click", function (event) {
                event.preventDefault();
                OnPageClick($(this).text() );
            });
            $("#tLinks a").live("click", function (event) {
                event.preventDefault();
                OnPageClick($(this).text() );
            });
        });
    }
    

    and your DDL onchange just call GetPage()

    <div class="rlinks" style="float:right;">Display&nbsp;
         @Html.DropDownList("RowsPerPage", ViewBag.PageList as SelectList, 
           new{onchange= "GetPage(this);"})&nbsp;Items per page
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.