How to change the name property in @ Html.EditorFor

3

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.
asked by anonymous 04.12.2015 / 15:23

2 answers

3
  

name and @Html.EditorFor are not changeable in name . You will need to change to id :

@Html.TextBoxFor(model => model.Nome, new { @class = "form-control input-lg required", Name = "name", @id = "name", @placeholder = "Name" }) 
    
04.12.2015 / 15:34
0

try to use Html.TextBoxFor (m => m.Email, new {@name="desired name"})

    
08.12.2015 / 17:08