0

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?

2
  • Where is Html.RowFor() coming from? Commented Jun 23, 2014 at 21:55
  • @mxmissile Exactly, what I thought at first? But then, I thought maybe its a control I've never heard of. But on googling it, I couldn't find anything, which suggests me there is no such thing!! Commented Jun 23, 2014 at 21:58

3 Answers 3

2

Adding classes can be done like so:

@Html.RowFor(x => x.Name, new { @class="control-group other-class" })
Sign up to request clarification or add additional context in comments.

Comments

1

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!!

3 Comments

Thx but I get Compiler Error Message: CS1501: No overload for method 'RowFor' takes 2 arguments
I'm not sure if @Html.RowFor control exists then (google search doesn't show as well). All razor elements do have extension methods for specifying html attributes.
Anyway, I've updated my answer considering all you want to show is a label for displaying "Name" property.
0
<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>

1 Comment

Down vote? There is no @Html.RowFor... There is a label and a text box in divs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.