ASP.NET MVC - How to Change Name Attribute of TextBoxFor

1

Is it possible to change the field name generated by @Html.TextBoxFor ? I did not find anything in Portuguese related to that.

I tried something like:

@Html.TextBoxFor(x => x.ToDate, new { name = "to" })

If I do for example, for ID or Style:

@Html.TextBoxFor(x => x.ToDate, new { style = "display: none;", id = "to" })

It works for both of the above, but not for the name.

Then is there a way to change the name generated by default by @Html.TextBoxFor ?

    
asked by anonymous 30.03.2017 / 21:04

2 answers

1

This attribute is case sensitive.

Use Name instead of name :

@Html.TextBoxFor(x => x.ToDate, new { Name = "to" })

Another example:

@Html.TextBoxFor(x => x.MeuCampo, new { Name = "blabla" })

    
30.03.2017 / 21:26
0

In the following it is possible to change the name of TextBoxFor

       @Html.TextBoxFor(x => x.ToDate, new
       {
           htmlAttributes = new
           {
               @class = "form-control",
               style = "display:none;",
               id = "to",
               name = "to"
           }
       })
    
30.03.2017 / 21:12