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("F开发者_StackOverflow中文版ooter")
}
else
{
<text>Default footer text here</text>
}
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.
Ohh.. stupid Razor (I actually like it). Maybe MS will find a better way? Smth like:
@RenderSection("Footer", () =>
{
blah...
})
精彩评论