Shawn Mclean
Shawn Mclean

Reputation: 57469

ASP.NET MVC RenderAction re-renders whole page

How do I prevent renderaction from rendering the masterpage and giving it back to me? I only want it to render 1 section, for eg.

The controller

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

The PaymentOptions View:

@model IEnumerable<Econo.Domain.PaymentBank>

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

The View

<div class="grid_10">

</div>

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

In grid_14, the header, footer and everything else gets rendered. Is there a way to prevent this?

Upvotes: 6

Views: 2477

Answers (2)

AaronShockley
AaronShockley

Reputation: 851

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

In Razor, partial views and full views have the same extension, so you need to explicitly use the PartialViewResult result type to specify a partial view.

Upvotes: 11

John Farrell
John Farrell

Reputation: 24754

This:

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

Has to use the overload so you can specify a master:

return View("PaymentOptions", "", settingService.GetPaymentBanks().ToList());

Upvotes: 0

Related Questions