I have the following class:
public class ModelHome
{
[Required]
[Display(Name = "Nome")]
public string Nome { get; set; }
[Required]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[Display(Name = "Messagem")]
[DataType(DataType.MultilineText)]
public string Mensagem { get; set; }
}
My Index
has a @Html.EditorFor
like this:
@Html.EditorFor(model => model.Nome, new { htmlAttributes = new { @class = "form-control input-lg required", @name = "name", @id = "name", @placeholder = "Name", @type = "text" } })
The annotation of Display
in the class I put to Labelfor
already works based on it. But this EditorFor
mounts the following HTML:
<input class="form-control input-lg required text-box single-line" data-val="true" data-val-required="O campo Nome é obrigatório." id="name" name="Nome" placeholder="Name" type="text" value="">
My observations:
- The imput takes the class, so the class is working.
- I have tried to pass the values in other parameters of the constructor, I could not.
- I tried to put
name
or@Html.EditorFor
(without the @), tb no I got it.