如何在ASP.NETMVC3.0中使用jQuery获取视图的Html

如何在ASP.NETMVC3.0中使用jQuery获取视图的Html,jquery,asp.net-mvc-3,Jquery,Asp.net Mvc 3,我想使用jquery获取视图的html,并想在另一个视图页面的div中显示此html。 我知道jquery的.html()方法,但它不符合我的要求。我做了很多搜索,但没有找到这个。请尽快发送答案。有一个正常的ActionResult,可以呈现部分 使用jQueryAjax调用ActionLink,例如 [HttpPost] public ActionResult partialview() { //do some process if you want to return PartialView

我想使用jquery获取视图的html,并想在另一个视图页面的div中显示此html。

我知道jquery的
.html()
方法,但它不符合我的要求。我做了很多搜索,但没有找到这个。请尽快发送答案。

有一个正常的ActionResult,可以呈现部分

使用jQueryAjax调用ActionLink,例如

[HttpPost]
public ActionResult partialview()
{
//do some process if you want to
return PartialView();
}
在jquery中

$.ajax({
url:'/Controller/partialview'
type:'POST',
cache:false,
success:function(data){// this handler is called upon successful completion of request

  //data contains the html generated by partial view
  // you can append it to a div or body as you like e.g
  $("#DivID").html(data);
  //$(data).appendTo("body"); 
  //etc
  //etc
},
error:function(jxhr){// error callback is called if something goes wrong
  if(typeof(console)!='undefined'){
   console.log(jxhr.status);
   console.log(jxhr.responseText);
    }
 }
});

您可以使用jQuery
load
从操作方法加载响应

在具有DIV的视图中具有此标记

<script type="text/javascript">  
 $(function(){
       $("#yourDivID").load("@Url.Action("YourController","YourAction")");
 });
</script>

确保您的
Views/your
文件夹下有查看
YourAction.cshtml
,其中有一些您想要显示的标记。

您能告诉我们您到目前为止尝试了什么吗?
public ActionResult YourAction()
{
  return View();
}