ASP.NET MVC editor templates and Html.EditorFor(...) - how to disambiguate the type name? -
when using html helper in razor syntax:
@html.editorfor(model => model.prop1)
... convention render view under views/<crtview|shared>/editortemplates/prop1typename.cshtml
.
so far good. notice if (qualified) type of prop1 my.org.ns.thetype
, file thetype.cshtml
rendered.
but if have model .prop1
, .prop2
, , :
prop1.gettype().fullname == "my.org.ns1.thetype"; prop2.gettype().fullname == "my.org.ns2.thetype"; //same type name different namespace
and call razor:
@html.editorfor(model => model.prop1) @html.editorfor(model => model.prop2)
...i can't display different views different types.
is there way disambiguate this?
maybe there's more know naming convention .cshtml
file?
you can use this overload specify name of editor use. this, name editortemplates first.cshtml
, second.cshtml
, in view, this.
@html.editorfor(model => model.prop1, "first") @html.editorfor(model => model.prop2, "second")
however, recommend avoiding reusing same type name in same project, if have different namespaces. cause confusion reading code, maybe down road. bigger issue framework not knowing template use.
Comments
Post a Comment