简体   繁体   English

Asp Mvc使用Ajax返回局部视图不起作用

[英]Asp Mvc Return a partial view with Ajax does not work

I am using MVC3 (Razor) with the Paging open source code here . 我在这里将MVC3(Razor)与Paging开源代码一起使用 The code call when hitting a button the Controller that has this code : 按下具有以下代码的Controller的按钮时的代码调用:

  [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". 这应该返回一个名为“ ListUsersTable”的PartialView。 It does return "ListUsersTable" but as a whole page instead of replacing the DIV. 它确实返回“ ListUsersTable”,但返回的是整个页面,而不是替换DIV。

Here is the code in the View : 这是View中的代码:

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

The button inside the ListUsersTable to do the Ajax call looks like that: ListUsersTable中用于执行Ajax调用的按钮如下所示:

   <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? 知道为什么代码没有替换DIV而是返回页面中的代码吗?

What JS files you have referenced? 您引用了哪些JS文件? 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. 在ASP.NET MVC3中,他们将AJAX功能从MicrosoftMvcAjax.js更改为jquery.unobtrusive-ajax.js,因此,如果您尚未这样做,请参考后者。

Also verify that the key "UnobtrusiveJavaScriptEnabled" on the web.config file is set to "true" 还要验证将web.config文件上的键“ UnobtrusiveJavaScriptEnabled”设置为“ true”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM