Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:46:19+00:00 2026-06-06T11:46:19+00:00

I am using Asp.net MVC 3 and Twitter Bootstrap. What I want is to

  • 0

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 problem, when it comes to the validation, I want it to generate HTML like this:

<div class="control-group error">
   <label for="field" class="control-label">OMG this label is so awesome: </label>
   <div class="controls">
      <input type="text" name="field" id="field" value="yeah" />
      <span class="help-inline">Eventually some error :C</span>
   </div>
</div>

Here is my HtmlHelper code:

@Html.LabelFor(x => x.Field)
@Html.EditorFor(x => x.Field)
@Html.ValidationMessagesFor(x => x.Field)

The problem is that I want the class error on outermost div to be set only if there actually is an error on this field. Other problem is that I don’t know how to enforce using span tag for errors. I could write my method in HtmlHelper, but it’d make me reimplement almost all of the functionality of the LabelFor, EditorFor and ValidationMessageFor. Is there a simpler way to do this? And what about the unobtrusive validation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:46:22+00:00Added an answer on June 6, 2026 at 11:46 am

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

    <div class="control-group @if (!ViewData.ModelState.IsValidField("Name")) { @Html.Raw("error"); }">
        @Html.LabelFor(model => model.Name, new {@class = "control-label"})
        <div class="controls">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name, null, new {@class = "help-inline"})
        </div>
    </div>
    

    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) {
        <div class="alert alert-error"><button class="close" dismiss="alert">x</button><!-- some text--></div>
    }
    

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Twitter Bootstrap, and trying to make my links ASP.Net MVC look nice.
I'm using ASP.NET MVC Validation. I want to know in my javascript functions whether
I'm using ASP.NET MVC 3 to build an application, but i'm having a problem
Using asp.net mvc 2 c#. I have a dynamic form. I want to get
Using Asp.Net MVC I was creating a file downloader. The problem with the built
Using ASP.Net Forms and ASP.Net MVC 3 (combined - we are in process of
Im using asp.net mvc 2.0. I have the following HtmlHelper extension: AdminOnly(HtmlHelper helper, IPrincipal
I'm using ASP.Net MVC 2, and I've got a slight problem. I need to
I'm deciding between using ASP.NET MVC, or standard ASP.NET Web Forms with URL routing
I am using ASP.NET MVC. I want to redirect to login page when session

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.