b3r3ch1t b3r3ch1t - 1 year ago 172
CSS Question

Attribute css in @Html.EditorFor

I have a textbox where I setup the attibute css "rounded".

I use this code

@Html.TextBoxFor(m => m.level, new { @class = "form-control rounded", @placeholder = "Level" })

When I run the browser renderizer this as

<input class="form-control rounded" id="level" name="level" placeholder="Level" type="text" " />

If I change to

@Html.EditorFor(m => m.level, new { @class = "form-control rounded", @placeholder = "Level" })

The browser rederizer as

<input class="text-box single-line" id="level" name="level" placeholder="Level" />

There are a way to use rounded with @Html.EditorFor?

What is the benefit to use @Html.EditorFor?

Answer Source

I think this is what you are looking for:

@Html.EditorFor(m => m.level, new { htmlAttributes = new { @class = "form-control rounded", @placeholder = "Level" }})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download