I have a PartialView which is updated using AJAX. The HTML elements are loaded correctly when updating the Div using AJAX, but the Telerik chart is not loaded. The datasource in the chart is not calling the Action method:
我有一个使用AJAX更新的PartialView。使用AJAX更新Div时,HTML元素正确加载,但未加载Telerik图表。图表中的数据源不是调用Action方法:
.DataSource(ds => ds.Read(read => read.Action("Movies_Read", "Movies")))
When the PartialView is initially loaded, not using AJAX, the datasource is calling the action method and the chart is loaded correctly.
最初加载PartialView时,不使用AJAX,数据源调用action方法并正确加载图表。
According to Telerik ASP.NET PartialView AJAX there needs to be this Javascript call for the OnSuccess event:
根据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;
}
I have tried the javascript mentioned in the documentation, but the get_data() and get_updateTarget() does not exists event though I havde added the MicrosoftAjax.js and MicrosoftMvcAjax.js. I suspect that these are deprecated. I have also tried other javascript functions but without any luck.
我已经尝试了文档中提到的javascript,但是get_data()和get_updateTarget()不存在事件,尽管我已经添加了MicrosoftAjax.js和MicrosoftMvcAjax.js。我怀疑这些已被弃用。我也尝试过其他的javascript函数,但没有任何运气。
My AJAX call is:
我的AJAX电话是:
@using (Ajax.BeginForm("UpdateMoviesChart", "Movies", new AjaxOptions { UpdateTargetId = "MoviesDiv", InsertionMode = InsertionMode.Replace, OnSuccess = "updatePlaceholder", }))
How do I load the Telerik Chart correctly when using AJAX?
使用AJAX时如何正确加载Telerik图表?
1 个解决方案
#1
0
In the view, the following script should be added to update the Div using Ajax:
在视图中,应添加以下脚本以使用Ajax更新Div:
View:
<div class="chart-wrapper"></div>
<script>
$(function () {
$.ajax({
url: "@(Url.Action("Movies_Read", "Movies"))",
success: function (data) {
$(".chart-wrapper").html(data);
}
});
})
</script>
Also the controller should be updated to have ActionResult as return type.
此外,应更新控制器以将ActionResult作为返回类型。
Controller:
public ActionResult RemotePartialView()
{
return PartialView("remote_partial_view");
}
#1
0
In the view, the following script should be added to update the Div using Ajax:
在视图中,应添加以下脚本以使用Ajax更新Div:
View:
<div class="chart-wrapper"></div>
<script>
$(function () {
$.ajax({
url: "@(Url.Action("Movies_Read", "Movies"))",
success: function (data) {
$(".chart-wrapper").html(data);
}
});
})
</script>
Also the controller should be updated to have ActionResult as return type.
此外,应更新控制器以将ActionResult作为返回类型。
Controller:
public ActionResult RemotePartialView()
{
return PartialView("remote_partial_view");
}