Good morning!
I am working on templates for EditorFor for the different types of data, specifically int
and double
in order to generate them in text type, with a oninput
that validates me not to enter incorrect information.
I started with the Int32 template and everything worked correctly, except that I can not find the return of how to get extra attributes
To be interpreted better;
The template (~ / Views / Shared / EditorTemplates / Int32.cshtml)
@model int?
@Html.TextBoxFor(model => model, null, new { @type = "text", @oninput = "this.value=this.value.replace(/[^0-9]/g,'')" })
When using it in a Vista , I get the desired result
@Html.EditorFor(x => x.CampoInt)
The problem is when I want to pass some extra attribute to EditorFor;
For example
@Html.EditorFor(x => x.CampoInt, new { htmlAttributes = new { @readonly = "readonly" } } )
The problem here is that both cases render the same thing.
<input oninput="this.value=this.value.replace(/[^0-9]/g,'')" type="text">
and what I intend, would be that in the second case, the following will be rendered
<input oninput="this.value=this.value.replace(/[^0-9]/g,'')" type="text" readonly="readonly">
I assume, that somehow I should receive a parameter within the Int32.cshtml template, but I've been looking for a while and can not find a solution, has anyone encountered a similar problem? p>
Thank you very much for the help!