Hoping to find a way when in MVC5 a Custom attribute or preferable the RegularExpressionAttribute decorates a property in the model the html control will contain it as another attribute of the control. E.g.
class CoolModel {
[CustomHtmlAttribute("hello")]
public string CoolValue {get;set;}
}
outputs...
<input type="text" customhtml="hello" />
Or something like that. So for the RegularExpressionAttribute the pattern attribute will be awesome.
class CoolModel {
[RegularExpressionAttribute("/d")]
public string CoolValue {get;set;}
}
outputs...
<input type="text" pattern="/d" />
I need this output without enabling the Javascript unobtrusive option. So I'm thinking in a way to specify some attribute in the model that gets push down to the view. Not sure if the Data annotations provider could do this job. Not sure if a Helper could be extended to get this result.
Help is appreciated.
@Html.TextBoxFor(m => m.SomeProperty, new { customhtml = "hello" }). Doing it using custom data annotations will be much more complexEditorTemplateswhich can be difficult to maintain across projects. The other alternative is to implement IMetadataAware to add the attributes tometadata.AdditionalValues, then create a set of custom html helpers that merge the attributes