I need to create a editor template for diferent type of data for example: for string I need a EditorTemplate for largeString and for shortstring
I see that the best way for me is using editor template. so can I use AdditionalMetadata? for something like this?
[UIHint("StringLarge")]
[AdditionalMetadata("width", "50px")]
public DateTime Date { get; set; }
My editor Template StringLarge.cshtml
@inherits System.Web.Mvc.WebViewPage<System.String>
if("have AdditionalMetadata"){
@Html.TextBox("", Model, new { @class = "StringLarge" })
}
else
{
@Html.TextBox("", Model, new { @class = "StringShort" })
}
Can I do that or just create separtes EditorTemplate for stringLarge and StringShort?
You can do that by writing a custom attribute implementing the IMetadataAware interface:
and then:
and finally inside your custom editor template (
~/Views/Shared/EditorTemplates/Strings.cshtml) you could check for the presence of this additional metadata: