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

  • Home
  • SEARCH
  • 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 7930415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:24:57+00:00 2026-06-03T20:24:57+00:00

I’ve only recently started learning ASP.NET MVC 3 and already faced with such problem.

  • 0

I’ve only recently started learning ASP.NET MVC 3 and already faced with such problem. I’m trying to use unobtrusive client validation in my project and there is strange thing about it. Here is code:

The first .cshtml file:

@model Task_2.Models.Worker
@{
  ViewBag.Title = "Edit:";
  Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Edit:</h2>

<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>
<script src="@Url.Content("~/Scripts/CausesValidation/Validation.js")"
type="text/javascript"></script>

@using (Html.BeginForm())
{
 @Html.ValidationSummary(true)
<fieldset>
    <legend>Worker</legend>

    @Html.HiddenFor(model => model.worker_id)

    <div class="editor-label">
        @Html.LabelFor(model => model.Surname)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Surname)
        @Html.ValidationMessageFor(model => model.Surname)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Name)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Name)
        @Html.ValidationMessageFor(model => model.Name)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Second_Name)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Second_Name)
        @Html.ValidationMessageFor(model => model.Second_Name)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Profession)
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(model => model.Profession,
              (IEnumerable<SelectListItem>)ViewData["ProfessionList"])
        @Html.ValidationMessageFor(model => model.Profession)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Age)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Age)
        @Html.ValidationMessageFor(model => model.Age)
    </div>
     <div class = "display-label">Projects:</div>
    <div class="editor-label">
        <table>
            @foreach (var item in (IEnumerable<string>)ViewData["WorkerTasks"])
            {
                 <tr>
                 <td>@Html.DisplayFor(modelitem => item)</td>
                 </tr>   
            }
        </table>
    </div>

    <div>
        @Html.ActionLink("EditTasks", "EditTasks", new { id = Model.worker_id })
    </div>
    <p>
        <input type="submit" value="Save"  name="Button_Edit_Worker"/>
    </p>
</fieldset>
}

And here is a model class for it:

public partial class Worker
{
    public Worker()
    {
        this.Tasks = new HashSet<Task>();
    }
    [Key]
    public System.Guid worker_id { get; set; }

    [RegularExpression(@"[A-ZА-ЯЁ][A-ZА-ЯЁa-zа-яё .()-]*$", 
          ErrorMessage = "Ошибка! Некорректный ввод!")]
    [Required(ErrorMessage = "Ошибка! Введите данные!")]
    public string Surname { get; set; }


    [RegularExpression(@"[A-ZА-Я][A-ZА-ЯЁЁa-zа-яё .()-]*$",
    ErrorMessage = "Ошибка! Некорректный ввод!")]
    [Required(ErrorMessage = "Ошибка! Введите данные!")]
    public string Name { get; set; }


    [RegularExpression(@"[A-ZА-ЯЁ][A-ZА-ЯЁa-zа-яё .()-]*$", 
      ErrorMessage = "Ошибка! Некорректный ввод!")]
    [Required(ErrorMessage = "Ошибка! Введите данные!")]
    public string Second_Name { get; set; }

    public string Profession { get; set; }



    [RegularExpression(@"[0-9]*$", 
      ErrorMessage = "Ошибка! Введите корректное число")]  
    [Range(16,100,ErrorMessage = "Ошибка! Введите число от 16 до 100")]
    [Required(ErrorMessage = "Ошибка! Введите данные!")]
    public int Age { get; set; }

    public virtual ICollection<Task> Tasks { get; set; }
}    
}

The second .cshtml file:

@model Task_2.Models.Task

@{
ViewBag.Title = "Edit";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Edit:</h2>

<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>
<script src="@Url.Content("~/Scripts/CausesValidation/Validation.js")"
type="text/javascript"></script>

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>Задание:</legend>

        @Html.HiddenFor(model => model.task_id)
    <div class="editor-label">
        @Html.LabelFor(model => model.Tusk_Name)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Task_Name)
        @Html.ValidationMessageFor(model => model.Tusk_Name)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Date)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Date)
        @Html.ValidationMessageFor(model => model.Date)
    </div>
    @ViewBag.message


    @if (ViewBag.source != "null")
    {
        <div>
          @Html.ActionLink("Back to task list of the current worker", 
          "EditTasks","Worker", new { id = new Guid(ViewBag.source) }, new { })
        </div>
    }

   <p>
        <input type="submit" value="Save" />
    </p>

</fieldset>
}

And a model class for it:

public partial class Task
{
    public Task()
    {
        this.Workers = new HashSet<Workers>();
    }
    [Key]
    public int task_id { get; set; }

    [RegularExpression(@"[A-ZА-ЯЁa-zа-яЁ0-9 .:()-]*$", 
     ErrorMessage = "Ошибка! Некорректный ввод!")]
    [Required(ErrorMessage = "Ошибка! Введите данные!")]
    public string Tusk_Name { get; set; }

    [DataType(DataType.Date)]//, ErrorMessage = "Ошибка! Некорректный ввод!")]
    [Required(ErrorMessage = "Ошибка! Введите данные!")]
    public System.DateTime Date { get; set; }

    public virtual ICollection<Worker> Workers { get; set; }
}

and I’ve used js file from here:
MVC3 Client Side Validation not working with an Ajax.BeginForm form

alert("hello");
$(function () {
$('form').submit(function () {

    $.validator.unobtrusive.parse($('form'));  //added
    alert("profit");
    if ($(this).valid()) {
        $.ajax({
            url: this.action,
            type: this.method,
            data: $(this).serialize(),
            success: function (result) {
                $('#result').html(result);
            }
        });
    }
    return false;
});
});

from the answer about Html.BeginForm().

So, the problem is that when I’m trying to submit the first form, it only alerts “hello” and posting. Server-side validation works correctly and it shoes error messages, but it ignores alert(“profit”) and whole client validation completely. The second form works correctly and fires client-side validation on submitting. The questions are: where is mistake and how I can force client-side validation work correctly?

  • 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-03T20:25:01+00:00Added an answer on June 3, 2026 at 8:25 pm

    Check out my posting here, I have some code that will help in the ajax updating/validation parsing:

    ASP.Net MVC: Can you use Data Annotations / Validation with an AJAX / jQuery call?

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.