I want to change the class/style of my @Html.EditorFor field. I read something about customizing the template, but there is no template folder in my porject (Views/Shared/ONLY_FILES_HERE). Sadly I am NOT working with MVC 5.1.
Also I DON'T want to use TextBoxFor, because of inputvalidation.
How can I achieve this?
Here is a snippet of my model:
public class CreateTableColumnModels
{
[RegularExpression(@"^[A-Za-z0-9]+$", ErrorMessage = "Use letters and numbers only please")]
[Display(Name = "Name")]
public string Name { get; set; }
I tried this:
@model QlikViewStammdaten.Models.CreateTableColumnModels
<div>
@Html.EditorFor(x => Model.Name, new { @class = "form-control" })
</div>
As already mentioned in the comments, it is better to add a class to
Html.TextBoxForand NOT@Html.EditorFor. Why? because@Html.EditorForrenders a template and that template could contain multiple controls (now to which one of those controls do you want to add the class?)... see Adding a class to EditorForIf you want numeric type, then add
@type = "number"Note: it is not
x => Model.Namebutm => m.NameI am sure you already know this, but
[Display(Name = "Name")]is redundant in your model, as the default display name is the variable name itself.