c# - Using @section inside Razor Helper -
we trying setup sections of our layout required configurable based on individual page. @ moment section.
@section floatingnav { <h1>@model.name <span class="release-year">@model.averagerating</span></h1> <ul class="sub-nav"> <li class="active"><a href="#episodes">episodes</a></li> <li><a href="#episodes">cast</a></li> <li>reviews</li> <li>related</li> </ul> }
this requires setup block in every new page wanted make process easier defaults , options configure using partial view. hoping setup razor helper such this.
@using system.web.mvc.html @helper floatingnav(string name, int rating) { @section floatingnav { <h1> name <span class="release-year">rating</span></h1> <ul class="sub-nav"> <li class="active"><a href="#episodes">episodes</a></li> <li><a href="#episodes">cast</a></li> <li>reviews</li> <li>related</li> </ul> } } @helper floatingnav(system.web.mvc.htmlhelper html, string viewname) { @section floatingnav { @html.partial(viewname) } } @helper floatingnav(system.web.mvc.htmlhelper html, string viewname, object model) { @section floatingnav { @html.partial(viewname, model) } }
so syntax implement
@layout.floatingnav(@model.name, @model.averagerating)
or
@layout.floatingnav("_simplenav", @model)
the issue though seems razor helpers not understand section syntax. there way include sections in razor helpers?
i don't think possible.
the @helper
, @section
syntax special directives compiling pages.
a helperresult
(a helper) doesn't know how define section.
the definesection method belongs webpagebase
.
you might have come @ different direction. using partial views instead of helpers fix problem.
Comments
Post a Comment