Is there a solution for using ASP.NET MVC 5 Html.EditorFor() and Bootstrap 3.0?

左心房为你撑大大i 提交于 2019-12-08 15:31:47

问题


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.


回答1:


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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/18386234/is-there-a-solution-for-using-asp-net-mvc-5-html-editorfor-and-bootstrap-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!