rball
rball

Reputation: 6955

Should I use Areas or RenderAction in ASP.NET MVC?

I've only read a few tidbits here and there about areas so far and haven't actually used them. Same for RenderAction, but I am running into a problem where I want to separate a certain piece of the page that is being used across all pages but has it's own functionality. With webforms I'd just be using a control. With MVC I was leaning towards the RenderAction method, and then bam today v2 preview 1 comes out with the "areas" support. RenderAction never really seemed all that support either being pushed out into the futures project.

My guess is that you'd want to now stay away from RenderAction as areas seems to have more future support. Right now though it seems that you'd need to create a entire new project just to have an "area"?

So I'd have a SideBar project, a BreadCrumb project, a UserLoggedIn project...yikes.

How the heck are people separating everything out? I can't be the only one that is running into this.

Upvotes: 2

Views: 807

Answers (1)

Robert Harvey
Robert Harvey

Reputation: 180787

Areas strikes me as a way to organize a large project into sectioned-off areas, whereas RenderAction has a specific purpose...providing a way to inject a "widget" into your page without having to push data into the view of every page that requires the widget, like you have to with a partial view.

It's a perfect way to fill specific parts of a web page, such as a menu or sidebar...One line of code in the view calls a specific method on a specific controller and returns only the data you need for that particular part of the page.


This should alleviate your concerns about RenderAction being supported.

FROM http://weblogs.asp.net/scottgu/archive/2009/07/31/asp-net-mvc-v2-preview-1-released.aspx

re: ASP.NET MVC V2 Preview 1 Released

Friday, July 31, 2009 11:29 AM by ScottGu @Dominic,

Will Html.RenderAction() be making an appearance in ASP.NET MVC V2?

Yes - that is on the current plan for V2.

Thanks,

Scott

Upvotes: 2

Related Questions