我的 Mvc 项目的共享文件夹中有 PartialView,现在我想在我的 Ajax 调用此 Partial 后刷新。我使用这个:
$('#Footer').load('/Views/_FooterReport.cshtml'); 我收到此错误:
获取 http://localhost:2885/Views/_FooterReport.cshtml 500(内部服务器错误)
<div id="updateAjax">
some Table
</div>
<div class="btnContainer">
some button here
</div>
<div id="Footer">
@Html.Partial("_FooterReport")
</div>
$.ajax({
url: url,
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: "html",
traditional: true,
data: parameters,
success: function (data, textStatus, jqXHR) {
$('#updateAjax').html(data);
//here How Can I Refresh or Reload my Partial in Footer
('#Footer').load('/Views/_FooterReport.cshtml');
},
error: function (data) {
}
});
最佳答案
这是一个 MVC 项目。这些请求将通过路由系统运行。获取此页面的 URL(例如:/home/page/
)并在 jQuery .load
语句中使用它。
<div id="Footer">
<div id="partToBeReplacedWithLoadData">
@Html.Partial("_FooterReport")
</div>
</div>
以及 jQuery 加载语句:
$('#Footer').load('/home/page/ #partToBeReplacedWithLoadData');
您将无法仅请求项目中的文件。它应该首先经过一条路线。如果 Controller 中有一个仅返回页 footer 分的路由和操作,也可以工作(例如:/home/footer/
)。
这不会重新加载整个页面,而是仅获取 #Footer
div 的内容。
关于javascript - ajax 调用后刷新局部 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31008802/