asp.net mvc - MVC render name of the view -
we have pages (lets call parent pages) calls other .aspx (lets call child pages) using renderaction.
what use in these parent pages kind of helper prints name of these child pages if in querystring appears debug=1 using like:
@html.autodiscoverwidgets()
its possible this? avoid put in every child page like:
@html.autodiscoverwidgets("nameofthechildview")
what have moment following extension method:
public static mvchtmlstring autodiscoverwidgets(this htmlhelper htmlhelper) { if (httpcontext.current.request.querystring["debug"].tostring() == "1") { return mvchtmlstring.create("hello"); } else { return mvchtmlstring.create(""); } }
you use following helper:
public static mvchtmlstring currentviewname(this htmlhelper htmlhelper) { var view = htmlhelper.viewcontext.view buildmanagercompiledview; if (view != null) { return mvchtmlstring.create(view.viewpath); } return mvchtmlstring.empty; }
and then:
@html.currentviewname()
Comments
Post a Comment