Search code examples
htmlasp.netasp.net-mvcasp.net-mvc-2html.textboxfor

MVC2: Impossible to change the name with TextBoxFor?


I want to manually define id and name for textbox like that:

<%: Html.TextBoxFor(model => model.Name, new { @id = "txt1", @name = "txt1" })%>

But only the id is changed, not the name attribute, why?

<input id="txt1" name="Name" type="text" value="">

Thank you!


Solution

  • You can't use the strongly typed lambda version for this, you'd need to use the older version

    Html.TextBox("txt1",new {@id = "txt1"})