View MVC3中的多个Renderactions

时间:2011-05-16 14:05:10

标签: asp.net-mvc-3

我在MVC3视图中有多个renderactions。

我希望获得部分视图,然后在parialviews进入时获得结果。

(就像页面上的一些占位符一样,然后页面会因为部分视图效果不佳而提交了渲染结果。)

我现在有几个Html.RenderAction(“Action”,“controller”);在主视图上使用不同的操作返回要呈现的一些部分视图。如何让它们反过来而不是等待渲染直到最后一个弹出?

我需要一些ajax还是使用AsyncController完成?

2 个答案:

答案 0 :(得分:1)

我总是喜欢使用jQuery ajax。你可以简单地将PartialView作为ajax动作结果返回,然后在jQuery(在浏览器端)用刚刚返回的PartialView替换你页面的specipic部分的内容。

快速简便,无需重新加载页面!

答案 1 :(得分:1)

看看这个:

$.ajax({
            type: "POST",
            data: { "supporterId": supporterId },
            url: '@Url.Action("ShowDetails")',
            success: function (result) {
                $("#popupDetails").html(result); - here you are replaceing content of you page with partial view returned by the action                   
            },
            error: function (error) {
                alert("error");
            }
        });

以下是行动:

        public ActionResult ShowDetails(int supporterId)
    {
        Supporter supporter = ... //get supporter object from the database
        return PartialView("Details", supporter);
    }