Reputation: 506
I am trying to add attributes like class
, style
.etc, using the razor helpers. How can I accomplish this?
Example: @Html.LabelFor(model => model.First)
Upvotes: 3
Views: 2040
Reputation: 1764
You need to use the New keyword and you can add HTML attributes like so:
@Html.LabelFor(model => model.First, new { @class = "test", id = "Lbl1"}))
Etc..You can keep adding HTML attributes inside the new {}.
Upvotes: 4
Reputation: 9095
@Html.LabelFor(model => model.First, new Dictionary<string, object>() { { "class", "class-name" }, { "style", "display:none" } });
Is that what u mean ?
Upvotes: 2