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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:24:27+00:00 2026-05-18T20:24:27+00:00

I am trying to get what I think is a simple example of using

  • 0

I am trying to get what I think is a simple example of using DataAnnotations on a model to drive the client side validation as well.

Here is my model…

 public class Person
 {
  [Required(ErrorMessage = "First Name Required")]
  public string FirstName { get; set; }
  [Required(ErrorMessage = "Last Name Required")]
  public string LastName { get; set; }
 }

Here is my controller…

 public class FriendsController : Controller
 {
  public ActionResult Create()
  {
   Person newFriend = new Person();
   return View(newFriend);
  }

  [HttpPost]
  public ActionResult Create(Person friendToCreate)
  {
   if (ModelState.IsValid)
   {
    // todo -- do something here
    return Redirect("/");
   }

   // Invalid - redisplay form with errors
   return View(friendToCreate);
  }
 }

and here is my view…

@model MvcApplication4.Models.Person
<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.4.4.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/MicrosoftMvcValidation.js")" type="text/javascript"></script>
</head>
<body>
    <h2>
        Create</h2>
    @{Html.EnableClientValidation();}
    @using (Html.BeginForm())
    { 
        <fieldset>
            <p>
                @Html.LabelFor(m => m.FirstName)
                @Html.TextBoxFor(m => m.FirstName)
                @Html.ValidationMessageFor(m => m.FirstName)
            </p>
            <p>
                @Html.LabelFor(m => m.LastName)
                @Html.TextBoxFor(m => m.LastName)
                @Html.ValidationMessageFor(m => m.LastName)
            </p>
            <p>
                <input type="submit" value="Create" />
            </p>
        </fieldset>
    }
</body>
</html>

The server side validation works just fine and the validation error messages appear as expected. However, I am not getting the client side validation to work. Is there something obvious that I am missing to make the client side validation appear?

  • 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-18T20:24:28+00:00Added an answer on May 18, 2026 at 8:24 pm

    Did you enabled Client side Validation on your web.config file?

    You can do it directly on the web.config file adding a couple of flags inside the appSetting section

    <configuration>
        <appSettings>
            <add key="ClientValidationEnabled" value="true"/>
            <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
        </appSettings>
    </configuration>
    

    or you can do it using pure c# code

    HtmlHelper.ClientValidationEnabled = true;
    HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
    

    I recommend you read Brad Wilson’s article Unobtrusive Client Validation in ASP.NET MVC 3

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

Sidebar

Related Questions

I'm trying to get this simple PowerShell script working, but I think something is
I think I should mention I'm trying to get Entity Framework\SQL server to do
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
I'm trying to get started with a simple audio application under .NET 3.5 (preferably
I'm using Salesforce.com Toolkit for PHP and I'm trying to output something I think
Trying to get my css / C# functions to look like this: body {
Trying to get an ASP application deployed; it worked for a while but then
Whilst trying to get our app working in Firefox (I'm a big proponent of
Im trying to get into some basic JavaFX game development and I'm getting confused

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.