5

I am using MVC3 (Razor) with the Paging open source code here. The code call when hitting a button the Controller that has this code :

  [Authorize(Roles = SystemConstants.ROLE_ADMINISTRATOR)]
  public ActionResult ListUsers(int? page)
  {
     int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
     var products = userToDisplay.ToPagedList(currentPageIndex, 5);
     return PartialView("ListUsersTable", products); 

  }

This should return a PartialView called "ListUsersTable". It does return "ListUsersTable" but as a whole page instead of replacing the DIV.

Here is the code in the View :

   <div id="listUserToBeUpdated">
       @Html.Partial("ListUsersTable", Model)
   </div>

The button inside the ListUsersTable to do the Ajax call looks like that:

   <div class="pager">
      @Ajax.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount, "ListUsers", new AjaxOptions { UpdateTargetId = "listUserToBeUpdated" })
   </div>

Any idea why the code is not replacing the DIV but return the code in the page instead?

1 Answer 1

6

What JS files you have referenced? In ASP.NET MVC3 they changed the AJAX functionality from MicrosoftMvcAjax.js to jquery.unobtrusive-ajax.js, so reference the latter if you're not doing so already.

Also verify that the key "UnobtrusiveJavaScriptEnabled" on the web.config file is set to "true"

Sign up to request clarification or add additional context in comments.

6 Comments

UnobtrusiveJavaScriptEnabled in the web.config is set to True.
I only have Jquery 1.4.4.js and the jquery-ui and jquery.validate referenced.
Try adding a reference to "jquery.unobtrusive-ajax.js" file.
Event with 1.6.1 is still does not return it in the container but as a page without the _Layout. It's seem the Ajax does the call because I can break inside the Controller when it should return the partial but the browser still do not act like an Ajax call...
I don't know the whole story, but the thing is that Microsoft first handled their AJAX using "MicrosoftMvcAjax.js" file, but with version 3, they implemented this "UnobtrusiveJavaScriptEnabled" tag for cleaner HTML rendering and I assume also better SEO, and are now using the jQuery AJAX plugin "jquery.unobtrusive-ajax.js"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.