Is there a solution for using ASP.NET MVC 5 Html.E

2019-06-15 14:38发布

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.

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-06-15 14:43

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

查看更多
对你真心纯属浪费
3楼-- · 2019-06-15 14:47

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.

查看更多
老娘就宠你
4楼-- · 2019-06-15 14:55

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

查看更多
登录 后发表回答