I want to set id to @Html.TextBox
so that I can access it in JavaScript. How can I do it?
@Html.TextBox("Output")
Note that I don't want to make a property for this.
CodePudding user response:
There is an overload to do this:
@Html.TextBox("Output", null, new { id = "put-your-id-here" })
Where I put null
is the value
argument, which is of type object
.
The third argument is the htmlAttributes
argument, which lets you define every attribute possible, you could also set classes passsing an object like this:
new { id = "main-card", class = "card card-body" }