ASP.NET MVC RenderAction重新呈现整个页面

时间:2011-05-27 17:32:14

标签: asp.net-mvc asp.net-mvc-3

如何防止渲染渲染母版页并将其还给我?我只希望它渲染1个部分,例如。

控制器

public ActionResult PaymentOptions()
{
    return View(settingService.GetPaymentBanks().ToList());
}

PaymentOptions视图:

@model IEnumerable<Econo.Domain.PaymentBank>

<h2>Payments</h2>
<!-- Stuff here -->

视图

<div class="grid_10">

</div>

<div class="grid_14">
@{Html.RenderAction("PaymentOptions", "Administrator");}
</div>

在grid_14中,页眉,页脚和其他所有内容都会被渲染。有办法防止这种情况吗?

2 个答案:

答案 0 :(得分:11)

public ActionResult PaymentOptions()
{    
    return PartialView(settingService.GetPaymentBanks().ToList());
}

在Razor中,部分视图和完整视图具有相同的扩展名,因此您需要显式使用PartialViewResult结果类型来指定部分视图。

答案 1 :(得分:0)

此:

return View(settingService.GetPaymentBanks().ToList());

必须使用重载,以便指定主服务器:

return View("PaymentOptions", "", settingService.GetPaymentBanks().ToList());
相关问题