Reputation: 1386
I've just downloaded VS 2013 because its new native support to the Bootstrap framework.
I create my forms, but they look different to original bootstrap ones. Problem is that it seems as razor and its "EditorFor" method, is not adding the "form-control" class needed for bootstrap.
I could add it as an html parameter, but then I would have to do that for each and every text field in my site.
How can I fix/modify Razor for it to automatically add this class for this objects?
Upvotes: 3
Views: 1870
Reputation: 1386
At the end as definitely it's not an error, it's just that .NET decided not to include this. http://www.asp.net/mvc/overview/releases/mvc51-release-notes#Bootstrap
The easiest way I foudn was using Jquery and adding the class to all the field that I need to in my case all the text-boxes en select lists.
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script>
$(".text-box").addClass("form-control");
$("select").addClass("form-control");
</script>
}
Upvotes: -1
Reputation: 55032
Try using TextBoxFor.
@Html.TextBoxFor(model => model.Title, new {style="border:1px solid red;"})
This works. and if you want to add any class
@Html.TextBoxFor(model => model.Title, new {@class="fooo"})
should work.
Upvotes: 2
Reputation: 16358
HTML classes must always be added manually. Nothing will do this for you automatically by default.
There are a few options for you:
Upvotes: 1