asp.net mvc - Find MVC template view by name -
i writing htmlhelper
extension , need search existence of template name. template in question may display or editor template depending on context. initial thought use viewengines.engines.findpartialview
method. however, appears method not searching ~/views/shared/displaytemplates
, ~/views/shared/editortemplates
directories.
suppose reason. after all, how viewengine
know whether return display or editor template without additional information of context?
so, leads question: how can search specific editortemplate/displaytemplate i've considered adding custom view engine viewengines
collection include these locations. i'm concerned, however, might problematic.
my main concern displaytemplate/editortemplate view might served unintended. else see problem?
better idea new specific displaytemplateviewengine
/editortemplateviewengine
instance when necessary , keep viewengines
collection clear of specific functionality?
there else i'm missing?
i absolutely love mvc framework open source! able determine, templatehelpers class (internal mvc runtime) databoundcontrolmode considered when rendering template. answer simple! have prefix template name appropriate template director. so, find display template:
var metadata = modelmetadata.fromlambdaexpression(expression, htmlhelper.viewdata); viewengines.engines.findpartialview( _controllercontext, string.format("displaytemplates/{0}", metadata.templatehint))
no additional view engines or routing required! in case you're interested in application, helper auto-generating ui components given model. wanted enable existence of custom template bypass automated rendering.
Comments
Post a Comment