razor - ASP.NET 3: What is a way to know what views and layouts are used? -
there following layouts , view:
_globallayout.cshtml
_subloyout.cshtml
somepage.cshtml
in _globallayout.cshtml want list of used layouts , current view name.
for example, in _globallayout.cshtml:
<html> <head> @html.some_method_that_will_know_about_used_layouts_and_view(); </head> <body> @renderbody(); </body> </html> the some_method_that_will_know_about_used_layouts_and_view return content using info used layouts , used view.
how can implement method?
the notion of current view doesn't make sense. haven't yet rendered body (@renderbody()) , expect view name? current action , controller though viewcontext:
@{ var currentcontroller = viewcontext.routedata.getrequiredstring("controller"); var currentaction = viewcontext.routedata.getrequiredstring("action"); } the main question remains though: why need , trying achieve it?
Comments
Post a Comment