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 8647905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:11:19+00:00 2026-06-12T13:11:19+00:00

I have a view that contains a partial view containing a WebGrid that pages

  • 0

I have a view that contains a partial view containing a WebGrid that pages via ajax.
However, I am having trouble getting the parent view to be aware of what page the WebGrid is on. What I’m trying to accomplish is this: I have a “create” button on the containing View that navigates to a new page, but I’d like it to pass the current page # as a query string parameter to the new page, so that if they cancel the creation, the original view will load with the previous page rather than loading the first page by default.

The problem I am seeing is, the Model of the parent view doesn’t change when the partial view’s grid updates. And, though I can create a method for the ajaxUpdateCallback, I haven’t figured out how to tell this method what the current page is.

My the pertinent sections of my code looks like this:
On the parent view:

<div id="divList">
    @Html.Partial("_MatterList", Model) //This is where the grid is defined
</div>
<br/>
<div id="newSection">

<input type="button" value="New Matter" onclick="newMatter();"></input>
</div>
<script type="text/javascript">

    var _Page; //I tried creating a javascript variable to hold the page, but can't get it to populate with anything but the default 1.

    function newMatter() 
    {
        var urlAction = "@Url.Action("Create", "Matter", new { area = "Admin" })";
        var subclientid = $("#SubClientID > option:selected").attr("value"); //defined in a form not displayed here
        var clientid = $("#ClientID > option:selected").attr("value");//defined in a form not displayed here
        redirect(urlAction, clientid, subclientid);

    }
    function redirect(urlAction, clientid, subclientid) {
        if(clientid > 0 || subclientid > 0 ) {
            urlAction += "?";
        }
        if(clientid > 0) {
            urlAction += "clientid=" + clientid;
            if(subclientid > 0) {
                urlAction += "&subclientid=" +subclientid;
            }
        }
        //I want to be able to add page in here as well. a la &page=_Page
        window.location = urlAction;
    }

In the _MatterList partial view:

 <div id="matterListing">

    @{

        var grid = new WebGrid<Matter>(null, rowsPerPage: 10, canSort: false, defaultSort: "Name", ajaxUpdateContainerId: "matterListing",ajaxUpdateCallback:"afterUpdate");
        grid.Bind(Model.Matters, rowCount: Model.TotalRows, autoSortAndPage: false);
        @grid.GetHtml(
            tableStyle: "table90",
            alternatingRowStyle: "tableAltRows",
            headerStyle: "tableHeaders",
            columns: grid.Columns(

                grid.Column(...  //there are a lot of columns, removed them because not important to the problem.


                )
                   )
    }
    <script type="text/javascript">
        function afterUpdate() {
            _Page = @Model.PageNumber; //I tried this but it only ever shows 1 because it evaluates when the page first loads.  What I need is for it to dynamically get the correct page at execution time.
        }
    </script>
</div>

I am thinking that what would be needed is for the afterUpdate method to take a parameter with the current page (i.e. call afterUpdate(2) instead of using @Model.PageNumber), but I don’t know how to force the WebGrid to pass that along on the callback. Does anyone have a solution to this issue?

  • 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-06-12T13:11:20+00:00Added an answer on June 12, 2026 at 1:11 pm

    The solution ended up being incredibly simple, I’m kind of embarrassed how long it took for me to come up with it.

    On the _MatterList partial view, I created form and placed a HiddenField with the page number:

    <form id="frmPage">
        @HiddenFor(model => model.PageNumber)
    </form>
    

    Then in the main page I modified newMatter() to extract that page, and redirect() to add it as a query string parameter:

    function newMatter() 
    {
        var urlAction = "@Url.Action("Create", "Matter", new { area = "Admin" })";
        var subclientid = $("#SubClientID > option:selected").attr("value"); //defined in a form not displayed here
        var clientid = $("#ClientID > option:selected").attr("value");//defined in a form not displayed here
        var page = $("#frmPage").find("#PageNumber").val();
        redirect(urlAction, clientid, subclientid, page);
    }
    
    function redirect(urlAction, clientid, subclientid, page)
    {
            if(clientid > 0 || subclientid > 0  || page > 1) {
                urlAction += "?";
            }
            if(clientid > 0) {
                urlAction += "clientid=" + clientid;
                if(subclientid > 0) {
                    urlAction += "&subclientid=" +subclientid;
                }
                if(page > 1) {
                    urlAction += "&page=" + page;
                }
            }
            else if(page > 0){
                urlAction += "page=" + page;
            }
            window.location = urlAction;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple pages containing the same partial view. The partial contains a form
I have a number of pages that include the same partial view which contains
I have an ASP.NET MVC Partial View that contains a Html.TextBox that is configured
I have a partial view that contains an img like so: <img src= alt=test
I have a view that has some jQuery to load a partial view (via
I have a view that contains many partial views and I need to pass
Lets say I have a partial view that contains both a checkbox and a
I have a View that contains a ParentModel, which contains 2 Models. I only
I have a view that contains two NSTextFieldCell s. The size at which these
I have a view model that contains a Product class type and an IEnumerable<

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.