开发者

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

开发者 https://www.devze.com 2023-01-16 09:50 出处:网络
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?

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...
})

0

精彩评论

暂无评论...
验证码 换一张
取 消