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 6473853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:30:57+00:00 2026-05-25T06:30:57+00:00

I need help figuring out how to succeed in implementing unobtrusive client-side validation of

  • 0

I need help figuring out how to succeed in implementing unobtrusive client-side validation of a field in my ASP.NET MVC 3 app. I can see that unobtrusive client-side validation is basically enabled, since MVC generates related HTML.

What I want to achieve in this case is to have validation of input to the Bugs editor (i.e., the corresponding <input> element) as I type, for testing purposes I’ve set the property’s max length to 2. When I test, I can tell that validation does not currently take place, so something is at least missing. So, the success criteria for this question is working client-side validation of the Bugs form field.

I can see one possible problem in the generated HTML: The Verbose property is not marked as Required in the model, but its corresponding <input> still gets the dataval=true attribute for instance, whereas the <input> for Bugs does not. Shouldn’t it be the other way around, as fields with validation rules should get dataval=true, to enable unobtrusive validation?

The code that should be relevant to understanding the case follows, please let me know if more info is required:

Options.cs:

public class Options
{
    [Required, StringLength(2)]
    public string Bugs;
    public bool Verbose;
}

Options.cshtml:

<script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<div id="options-form">
  @using (Html.BeginForm())
  {
    @Html.ValidationSummary(true)
    <fieldset>
      <legend>Options</legend>
      <div class="editor-label">
        @Html.LabelFor(model => model.Bugs)
      </div>
      <div class="editor-field">
        @Html.EditorFor(model => model.Bugs)
        @Html.ValidationMessageFor(model => model.Bugs)
      </div>
      <div class="editor-label">
        @Html.LabelFor(model => model.Verbose)
      </div>
      <div class="editor-field">
        @Html.CheckBoxFor(model => model.Verbose)
        @Html.ValidationMessageFor(model => model.Verbose)
      </div>
   </fieldset>
  }
</div>

The two editors (for Bugs and Verbose) are rendered as follows:

<div id="options-form">
<form action="/Options" method="post">
  <fieldset>
    <legend>Options</legend>
      <div class="editor-label">
        <label for="Bugs">Bugs</label>
      </div>
      <div class="editor-field">
        <input class="text-box single-line" id="Bugs" name="Bugs" type="text" value="" />
        <span class="field-validation-valid" data-valmsg-for="Bugs" data-valmsg-replace="true"></span>
      </div>
      <div class="editor-label">
        <label for="Verbose">Verbose</label>
      </div>
      <div class="editor-field">
        <input data-val="true" data-val-required="The Boolean field is required." id="Verbose" name="Verbose" type="checkbox" value="true" /><input name="Verbose" type="hidden" value="false" />
        <span class="field-validation-valid" data-valmsg-for="Verbose" data-valmsg-replace="true"></span>
      </div>
    </fieldset>
  </form>
</div>
  • 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-05-25T06:30:57+00:00Added an answer on May 25, 2026 at 6:30 am

    Bugs and Verbose are public fields in this code, not properties. Make them properties and that should fix it.

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

Sidebar

Related Questions

http://jsfiddle.net/nicktheandroid/ZSvHK/ I need help figuring out how to get this right, problems listed below.
I need help with the best practice to localize asp mvc apps, I saw
I need help figuring out why my authentication ticket is expiring after about an
I need help figuring out some regular expressions. I'm running the dig command and
I need help figuring out how to change out the view in my application.
I need help figuring out these php print (echo) statements and where to place
Need help in figuring out a way to fetch a particular block of content
I need some help figuring out why the following scenario does not work. I'm
Need some php help in figuring out how use this array I created, but
Need help figuring out how to do this. My code: my %hash; $hash{'1'}= {'Make'

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.