Override "id" attribute for Html.EditorFor - does not work

Trying to override the id attribute for Html.TextBoxFor (MVC 3) so that it looks like this:

<input type="text" name="Password" id="@idPasswordTextBox" value="@Model.Password" />

where "idPasswordTextBox" is defined as: string idPasswordTextBox = "passwordText_"+@Model.Key;in the same cshtml file.

This works fine if I use like:

<input type="text" name="Password" id="@idPasswordTextBox" value="@Model.Password" />

but it doesn’t work if I do it like this:

@Html.TextBoxFor(model => model.Password, new { id = "@idPasswordTextBox" })

It looks like the id attribute is getting corrupted. What am I missing? Can anyone help? I am the new bee at ASP.net.

Thanks in advance.

+5
source share
1 answer

, . @idPasswordTextBox TextBoxFor. , , , . @ , .

, , .

@Html.TextBoxFor(model => model.Password, new { id = @idPasswordTextBox })
+5

All Articles