I got some great feedback on mapping PortableAreas to MasterPages and ContentPlaceHolders:

“Wouldn't this need to be repeated for every PA that was used by the host? Could this be changed to just globally map "PageTitle" to Title, "BodyContent" to Content, etc.?” – Steve Michelotti

Yeah, he’s right.  Seems ridiculous to have to map each area individually when they’ll all be using the same configuration.  Enter MapAll():

PortableAreaContent.MapAll()

    .Master("~/Views/Shared/PA.master")

    .Title("PageTitle")

    .Body("BodyContent");

 

PortableAreaContent.Map<AnotherPortableAreaMap>()

    .JavaScript("ScriptContent");

 

AreaRegistration.RegisterAllAreas();


You’ll notice that I changed “Content” to “PortableAreaContent” in the above snippet.  I did that because I thought that “Content” was too vague, and that the new name expressed more intent.

The MapAll() method basically works the same as the Map<>() method, except that it sets the default values for all other PortableAreaMaps.  The Map<>() method is still available, and in the above snippet it is used to configure a special mapping for a JavaScript ContentPlaceHolder. 

Adding a way to globally set MasterPages and ContentPlaceHolders further simplified the mapping scenarios, while still leaving it robust for slightly more complicated ones.

Sunday, May 23, 2010 6:11:49 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
MvcContrib | Portable Areas
Comments are closed.

John Nelson

mugshot I am a passionate C# Developer working in ASP.NET on an e-commerce solution for ticketing software. I work across all of the application layers, including server side functionality, and client side programming with jQuery and MS Ajax. Although my full time job is in WebForms, I spend many of my off hours working with MVC. I am especially interested in productivity and good programming practices.

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
johncoder.com
Statistics
Total Posts: 41
This Year: 17
This Month: 0
This Week: 0
Comments: 4