[英]ASP.NET MVC AJAX PartialView Telerik UI not loading
我有一個PartialView,它使用AJAX更新。 使用AJAX更新Div時,將正確加載HTML元素,但不會加載Telerik圖表。 圖表中的數據源未調用Action方法:
.DataSource(ds => ds.Read(read => read.Action("Movies_Read", "Movies")))
最初加載PartialView而不使用AJAX時,數據源正在調用action方法,並且圖表已正確加載。
根據Telerik ASP.NET PartialView AJAX ,需要對OnSuccess事件進行以下Javascript調用:
<script type="text/javascript">
function updatePlaceholder(context) {
// the HTML output of the partial view
var html = context.get_data();
// the DOM element representing the placeholder
var placeholder = context.get_updateTarget();
// use jQuery to update the placeholder. It will execute any JavaScript statements
$(placeholder).html(html);
// return false to prevent the automatic update of the placeholder
return false;
}
我已經嘗試了文檔中提到的javascript,但是盡管我已經添加了MicrosoftAjax.js和MicrosoftMvcAjax.js,但get_data()和get_updateTarget()並不存在。 我懷疑這些已過時。 我也嘗試了其他javascript函數,但沒有任何運氣。
我的AJAX電話是:
@using (Ajax.BeginForm("UpdateMoviesChart", "Movies", new AjaxOptions { UpdateTargetId = "MoviesDiv", InsertionMode = InsertionMode.Replace, OnSuccess = "updatePlaceholder", }))
使用AJAX時如何正確加載Telerik Chart?
在視圖中,應添加以下腳本以使用Ajax更新Div:
視圖:
<div class="chart-wrapper"></div>
<script>
$(function () {
$.ajax({
url: "@(Url.Action("Movies_Read", "Movies"))",
success: function (data) {
$(".chart-wrapper").html(data);
}
});
})
</script>
另外,控制器應更新為將ActionResult作為返回類型。
控制器:
public ActionResult RemotePartialView()
{
return PartialView("remote_partial_view");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.