how to set id to Html.TextBox item on MVC

You can set ID of a textbox like this.

@Html.TextBoxFor(item => item.OperationNo, new { id = "MyId" })

OR

@Html.TextBoxFor(item => item.OperationNo, htmlAttributes: new { id = "MyId" })

Output:

<input ... id="MyId" name="OperationNo" type="text" />

Leave a Comment