How to change the name property in @Html.Editorfor

Asked

Viewed 1,744 times

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; }

    }

Man Index has a @Html.EditorFor thus:

@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 the Labelfor already work 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="">

The estate name ALWAYS COMES Name, how I make her come name how are you in the @Html.EditorFor ?

My remarks:

  • imput takes the class, so @class is working.
  • I have already tried to pass the values on other constructor parameters, couldn’t.
  • I tried to put @name="name" or name="name" (without @), also not got.

2 answers

3


The estate name ALWAYS COMES Name, how I make her come name how are you in the @Html.EditorFor?

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

@Html.TextBoxFor(model => model.Nome, new { @class = "form-control input-lg required", Name = "name", @id = "name", @placeholder = "Name" }) 
  • The code is that right there that you put? I’m not able to make appear name no...

  • I’m sorry, I misspelled. Look now.

0

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.