It is my understanding that the location is:
~/Views/Shared/EditorTemplates/ViewModelName
However I have many Views folders using areas. Can I define the file to use with some parameter of the call to the
@Html.EditorFor( ...
Those are default lookup paths which RazorViewEngine will search for editor template, in this order:
"~/Areas/{area}/Views/{controller}/EditorTemplates/{templateName}.cshtml",
"~/Areas/{area}/Views/Shared/EditorTemplates/{templateName}.cshtml",
"~/Views/{controller}/EditorTemplates/{templateName}.cshtml",
"~/Views/Shared/EditorTemplates/{templateName}.cshtml",
If not specified, templateName
value defaults to object type (in your case 'ViewModelName'). If template with this name is not found by MVC will fall back to resolve rendering using known build-in templates (int, string, collection, object, etc).
You can specify template name to override defaults:
@Html.EditorFor(m => m.MyDate, "_MyTemplate")
You can also specify relative paths:
@Html.EditorFor(m => m.MyDate, "../_MyTemplate")
You cannot specify full paths in any form (ex:"~/Views/Custom/EditorTemplates/ViewModelName"
) and you should never specify extension in template name (ex: '_MyTemplate.cshtml'
, or '_MyTemplate.vbhtml'
)!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With