0

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.

Ali Vojdanian
  • 2,067
  • 2
  • 31
  • 47

1 Answers1

1

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" }
buda_pest
  • 46
  • 1
  • 5