Integrating Twitter Bootstrap with Asp.net MVC 3 forms

后端 未结 6 1772
有刺的猬
有刺的猬 2021-01-31 09:59

I am using Asp.net MVC 3 and Twitter Bootstrap. What I want is to integrate both of them. The big problem for me is forms. I am using the HtmlHelper and it is a pro

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 10:12

    I encountered the same challenge and with some help for the labels (see below), here is what I got :

    @Html.LabelFor(model => model.Name, new {@class = "control-label"})
    @Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name, null, new {@class = "help-inline"})

    Html.LabelFor implementation : https://stackoverflow.com/a/6722082

    I didn't try with the unobstrusive validation, but it seems you just have to activate it.

    If you are looking for a global error, you should use something like :

    @if (ViewData.ModelState.IsValid == false) {
        
    }

    There is a live example (in french) here : http://ws.sherbrow.fr/auth

    The whole project source code should be available some time soon (see my profile - or ask me directly).

提交回复
热议问题