Reputation: 525
Is there any way to add bootstrap classes like form-control to asp.net mvc html helper methods like @html.Textbox("searchString");?
this is the code I have in the view
@this is the html output for the search bar taking searchstring param from controller in htmlhelper@
@using (Html.BeginForm())
{<div class="jumbotron">
<div class="row">
<div class="col-md-12">
<p>
Search: @Html.TextBox("SearchString")
<input class="btn btn-info" type="submit" value="Search" />
</p>
</div>
</div>
</div>
}
It seems like everything is playing nice with bootstrap except the @Html.Textbox and its messing up my UI. is there a way to affect the @Html.Textbox with bootstrap form-control class?
ps the "SearchString" variable comes from my controller.
Upvotes: 1
Views: 4024
Reputation: 17139
One variation of the @Html.TextBox
helper takes an anonymous object
that you can use to pass in HTML attributes. You would use it like:
@Html.TextBox("SearchString", null, new { @class = "form-control" })
Upvotes: 0
Reputation: 12452
Yes.
You have the possibility to add HtmlAttributes:
@Html.TextBox("SearchString", null, new { @class = "form-control" })
And if you're using a property from your @model:
@Html.TextBoxFor(m => m.Property, new { @class = "form-control" })
Upvotes: 1