Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a better way to specify default section content in asp.net mvc razor layouts?

With the asp.net mvc web form engine, you could define a content placeholder and specify the default content. How is this done with Razor engine?

I found this example in Phil Haack's Defining Default Content For A Razor Layout Section - but it seems like there would be a better way.

_Layout.cshtml:

@if (IsSectionDefined("Footer")) 
{ 
  @RenderSection("Footer") 
} 
else 
{ 
  <text>Default footer text here</text> 
}
like image 951
bkaid Avatar asked Nov 05 '22 08:11

bkaid


1 Answers

Unfortunately not.

I looked into writing an Html helper but the view isn't available to the htmlHelper and I haven't been able to see a way, at least right away, that would allow you to do it. It might be something worth requesting on http://aspnet.codeplex.com as I've seen others request this functionality on a couple of the blogs.

like image 138
Buildstarted Avatar answered Nov 09 '22 12:11

Buildstarted