You cannot do that with the EditorFor
helper simply because you don't know what template will be used. You could achieve it but you will need to write a custom editor template. For example this could be achieved by overriding the default editor template
and taking into account the second parameter which represents an additional view data.
Here's an example of how such a custom editor template could look for string types (~/Views/Shared/EditorTemplates/string.cshtml
):
@Html.TextBox(
"",
ViewData.TemplateInfo.FormattedModelValue,
ViewData
)
and then you could use it like that:
@Html.EditorFor(model => model.name, new { @class = "myclass" })
With the CheckBoxFor helper you could do that:
@Html.CheckBoxFor(m => m.RememberMe, new { @class = "myclass" })