11

Question:

Is there a way to make the ASP.NET MVC 5 Html.EditorFor() form helpers work with the changed Bootstrap 3 form syntax.*?

Discussion (of what I have looked into already):

It appears there are a many SO questions regarding hacks to override the built in MVC helpers. In general, it doesn't look like there is a supported solution to modify the helper HTML. (please correct me if I'm wrong)

Therefore, is it possible to build a shim CSS file that adapts the Helper's 2.3.x HTML to the look of the Bootstrap 3 form CSS? It seems that most other aspects of MVC 5 are Bootstrap 3 compatible except for the auto form fields.

The benefit of a CSS shim, is that it could be removed when ASP.NET MVC is updated to support the newer Bootstrap syntax natively.

*I acknowledge that ASP.NET MVC 5 is still in beta and has been developed for Bootstrap 2.3.x since 3.0 was also in beta at the time.

Dan Sorensen
  • 11,403
  • 19
  • 67
  • 100
  • I have heard that the RTM of MVC 5 will include support for Bootstrap 3.0, although I cannot find that blog post or release note at the moment. If you have info on this, please post a link. – Dan Sorensen Sep 30 '13 at 17:52
  • Dan, have you figured out a solution since you posted this? We are now encountering the same problem you describe where we can't attach the new Bootstrap 3 `form-control` class to inputs rendered with Html.EditorFor(). Are we still SOL? – John Washam Dec 09 '13 at 20:54
  • Frankly, I haven't checked recently. I meant to re-test this issue once the final version of Visual Studio 2013 came out to see if there was any improvements. Have you checked to see if there are an NuGet updates available for your bootstrap and MVC components? – Dan Sorensen Dec 09 '13 at 22:08
  • We just upgraded our solution to use MVC 5 and manually integrated Bootstrap 3, but as far as I'm aware, there is still no way to get HTML attributes into an EditorFor without doing a custom attribute implementation or something. Just didn't know if you had any luck with any other solution. Thanks for the response! – John Washam Dec 09 '13 at 22:43

3 Answers3

16

There is now a MS solution for the MVC helpers.

It's currently Pre-release, but MVC5.1 has

MVC 5.1 is released and has

Bootstrap support in views

We now allow passing in html attributes in EditorFor as an anonymous object

Example code...

@Html.EditorFor(model => model, new { htmlAttributes = new { @class = "form-control" }, })

More info on this here.... http://www.asp.net/visual-studio/overview/2013/aspnet-and-web-tools-20132-preview-for-visual-studio-2013-release-notes#mvcbootstrap

.. and install instructions here... http://blogs.msdn.com/b/webdev/archive/2013/12/09/asp-net-and-web-tools-2013-2-preview-for-visual-studio-2013.aspx

Community
  • 1
  • 1
dave heywood
  • 791
  • 8
  • 13
  • 3
    Note that this update has now been released formally.. http://blogs.msdn.com/b/webdev/archive/2014/01/20/announcing-the-release-of-asp-net-mvc-5-1-asp-net-web-api-2-1-and-asp-net-web-pages-3-1.aspx – dave heywood Jan 27 '14 at 14:12
8

TwitterBootstrapMVC looks like a good abstraction over Bootstrap 3 - great with the Fluent API, BUT sending credit card details for a trial? Nope.

gumaflux
  • 330
  • 2
  • 13
2

TwitterBootstrapMVC is a library of html helpers, main focus of which is to simplify writing html related to Twitter Bootstrap forms.

As of today it works with Twitter Bootstrap 2 syntax. However, support for Twitter Bootstrap 3 will be released shortly.

If you used helpers from tihs library, transition from v2 to v3 should be painless.


Disclaimer: I'm the author of TwitterBootstrapMVC
The BMVC for Bootstrap 3 is not free.

Dmitry Efimenko
  • 10,973
  • 7
  • 62
  • 79