senzacionale
senzacionale

Reputation: 20916

ASP.NET MVC and @Html.RowFor(x => x.Name) how to add CSS

Now I have code like:

@Html.RowFor(x => x.Name)

but I want to ocnvert it to my template like:

<div class="control-group">
<label class="control-label" for="focusedInput">Name</label>
<div class="controls">
<input class="input-xlarge focused" id="Name" type="text" value="Name">
</div>
</div>

How can I add all the classes?

Upvotes: 0

Views: 130

Answers (3)

Satwik Nadkarny
Satwik Nadkarny

Reputation: 5135

When making use of razor syntax, you can add html attributes as such:

@HtmlSomeControl(x=> x.Whatever, new { id="idNameOfControl", @class="classNameOfControl" })

So your code would be essentially become:

@Html.LabelFor(x => x.Name, new { @class="control-group control-label" )
@Html.DropDownListRowFor(x => x.SelectedCountryId, Model.Country.ViewModel.Countries, new { @class="controls input-xlarge focused")

Hope this helps!!

Upvotes: 1

BenG
BenG

Reputation: 15154

<div class="control-group">
@HtmlLabelFor(x => x.Name, new { @class="control-label" })
<div class="controls">
 @HtmlTextBoxFor(x => x.Name, new {@class="input-xlarge focused", @id="Name" })
</div>
</div>

Upvotes: 0

Rodney G
Rodney G

Reputation: 4826

Adding classes can be done like so:

@Html.RowFor(x => x.Name, new { @class="control-group other-class" })

Upvotes: 2

Related Questions