且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在MVC ..中单击链接时在主视图中呈现局部视图?

更新时间:2023-02-25 18:17:37

Microsoft在此发布了

That's where Microsoft came out with the Ajax.ActionLink. That's one option; I personally like jQuery better, so I do something like:

$.ajax({

   type: "get",
   url: "@Url.Action("Partial", "Controller"),
   success: function(d) { 
     /* d is the HTML of the returned response */
     $("#SomeParentIDForSection").html(d); //replaces previous HTML with action
   }
});

只需确保您的控制器返回局部视图:

Just make sure your controller returns a partial view:

public ActionResult Partial()
{
    var model = ..
    //init work

    return PartialView(model);
}

有关更多信息和其他方法,请参见以下参考资料:

See these references for more information and some other approaches: