我查过这个问题 https://stackoverflow.com/questions/4888521/asp-net-mvc3-razor-views-and-partialviews-with-ajax-postbacks它解决了我最初的问题。但我不希望仅在用户单击链接时呈现部分视图,我想在加载页面时呈现部分视图,并且可能在加载部分视图时显示进度指示器。
如何实现这一目标?
非常感谢您阅读本文。
如果你想加载页面,然后通过ajax加载部分视图,你可以创建一个ActionMethod
这样做是这样的:
public ActionResult Create()
{
var model = new MyModel();
if (Request.IsAjaxRequest())
{
return PartialView( "_Partial", model.PartialModel );
}
else
{
return View( model );
}
}
然后在您的页面中执行以下操作:
$(function(){
$(document).ajaxStart(function () {
//show a progress modal of your choosing
showProgressModal('loading');
});
$(document).ajaxStop(function () {
//hide it
hideProgressModal();
});
$.ajax({
url: '/controller/create',
dataType: 'html',
success: function(data) {
$('#myPartialContainer').html(data);
}
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)