Asp.net mvc 3 如何在ASP.NETMVC3Razor视图中使用Ajax和Jquery加载页面节?
我在ASP.NETMVC3网站上工作,该网站使用Razor视图引擎和Jquery 在主页(或任何相关页面)上,我想使用ajax加载部分内容,类似于iGoogle 我是说页面加载Asp.net mvc 3 如何在ASP.NETMVC3Razor视图中使用Ajax和Jquery加载页面节?,asp.net-mvc-3,jquery,razor,Asp.net Mvc 3,Jquery,Razor,我在ASP.NETMVC3网站上工作,该网站使用Razor视图引擎和Jquery 在主页(或任何相关页面)上,我想使用ajax加载部分内容,类似于iGoogle 我是说页面加载 我想调用一些HttpGet操作方法,每个方法都返回一些 Html内容 在我得到回应之前,这些分区显示“加载”图形 我知道Ajax.BeginForm和Ajax.ActionLink,但在这两种情况下,我都需要单击一些UI元素;我不知道如何在页面加载/文档中使用它们。准备好了吗 即使我得到了一些指导,但没有得到精确/完
- 我想调用一些HttpGet操作方法,每个方法都返回一些 Html内容
- 在我得到回应之前,这些分区显示“加载”图形
即使我得到了一些指导,但没有得到精确/完整的代码,我也会心存感激。好的,让我们给你一些指导,我将在jquery中展示一些代码,因为它非常简单。我们走吧 Html 在javascript库文件中
function LoadData(target, url){
$.ajax({
beforeSend: startAnimation(target),
url : url,
success : function(result){ $(target).html(result); },
complete : stopAnimation(target)
});
}
function startAnimation(target){
//..add a loading image on top of the target
}
function stopAnimation(target){
// remove the animation gif or stop the spinning, etc.
}
您的服务器端代码
public ActionResult ActionName() {
... do things to get your model populated ...
return PartialView("SomeView", yourmodel);
}
其他想法:
- 这段粗略的代码将部分视图加载到div中。当dom准备就绪时,asychonous调用开始李>
- 有关jQueryAjax文档,请参见
- 我喜欢使用spin.js来显示加载图标,因为它非常简单和小
function LoadData(target, url){
$.ajax({
beforeSend: startAnimation(target),
url : url,
success : function(result){ $(target).html(result); },
complete : stopAnimation(target)
});
}
function startAnimation(target){
//..add a loading image on top of the target
}
function stopAnimation(target){
// remove the animation gif or stop the spinning, etc.
}
public ActionResult ActionName() {
... do things to get your model populated ...
return PartialView("SomeView", yourmodel);
}