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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:16:34+00:00 2026-05-31T21:16:34+00:00

In an MVC3 application I have a view rendering two Ajax partial views: a

  • 0

In an MVC3 application I have a view rendering two Ajax partial views: a Create partial view and a List one. In the Create partial view I try to fire client validation on OnBegin event, but this does not happen.

The error messages I get, when I force errors, are the one indicated in the model annotations, and not the ones I define in the validation function called OnBegin (e.g.:

  • leaving the event place empty, I get “The event place is required” (annotation) instead of “Where did it take place?” (FieldsValidation function),

  • for the event description I get “The event description is required” (annotation) instead of “Tell us sth about it!” (FieldsValidation function)

  • and the validation summary message sais “Error on creation. Please retry after corrections.” instead of “Save failed. Please correct errors and retry.“(FieldsValidation function)).

I tried to put a breakpoint in the FieldsValidation function, but it was never reached.
Just to make sure, I also tried to call OnBegin a function displaying an alert (after the test I restored the original call to FieldsValidation function):

    function toDoOnBegin() { alert("This is onBegin"); }

The alert never displays!

If all fields are properly filled in, the event is correctly created and displayed in the event list (the other partial view). The problem is uniquely the function call OnBegin.

Please explain me what did I do wrong, did I miss to include something or what else is it?

Thank you truly.

Web.config

<appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

Model:

    public partial class Event
{
    public int client_ID { get; set; }

    [Required(ErrorMessage="The event date is required")]
    [DataType(DataType.Date, ErrorMessage="The event date is invalid")]
    public System.DateTime event_date { get; set; }

    [Required(ErrorMessage="The event place is required")]
    public string event_place{ get; set; }

    [Required(ErrorMessage="The event description is required")]
    public string event_description{ get; set; }
}

_Layout.cshtml :

Style sheets

<link href="@Url.Content("~/Content/styles.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/nivo-slider.css")" rel="stylesheet" type="text/css" media="screen"/>
<link href="@Url.Content("~/Content/themes/redmond/jquery-ui-1.8.18.custom.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/jquery.timepicker.css")" rel="stylesheet" type="text/css" />  
<link href="@Url.Content("~/Content/jquery.alerts.css")" rel="stylesheet" type="text/css" media="screen"/>

jQueries for datetimepicker plugin needed on several other pages

<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.18.custom.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.core.min.js")"  type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.slider.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.datepicker.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.datepicker-fr.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-timepicker-addon.js")" type="text/javascript"></script>

jQueries for other application components

<script src="@Url.Content("~/Scripts/jquery.alerts.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/OJscript.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.nivo.slider.pack.js")" type="text/javascript"></script>

jQueries for validation

<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/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>

Index.cshtml

@model MyApp.ViewModels.EventViewModel

@{
    ViewBag.Title = "Events";
}

<div id="divUpdateable">
    @Html.Partial("_Create", Model)
</div>
<div id="divList">
    @Html.Partial("_ListEvents", Model.EventsList)
</div>

_Create.cshtml

@model MyApp.ViewModels.EventViewModel

<script type="text/javascript">

    function FieldsValidation() {
        $("#idformCreate").validate({

            errorContainer: $($('div.validation-summary-errors')),
            errorLabelContainer: $("ul", $('div.validation-summary-errors')),
            wrapper: 'li',
            errorClass: "input-validation-error2",

            rules:
                {
                    'Event.event_date':
                    {
                        required: true
                    },
                    'Event.event_place':
                    {
                        required: true
                    },
                    'Event.event_description':
                    {
                        required: true
                    }
                },
            messages:
                {
                    'Event.event_date':
                    {
                        required: "Date is required"
                    },
                    'Event.event_place':
                    {
                        required: "Where did it take place?"
                    },
                    'Event.event_description':
                    {
                        required: "Tell us sth about it!"
                    }
                }

        }).form();

        if (!$("#idformCreate").valid()) {
            $("div.validation-summary-errors span").html("Save failed. Please correct errors and retry.");
            return false;
        }

        return true;
    }
</script>

@using (Ajax.BeginForm("Create", "Event", new { clientID = Model.Event.client_ID }, new AjaxOptions
{
    UpdateTargetId = "divUpdateable",
    OnBegin = "FieldsValidation",
    InsertionMode = InsertionMode.Replace,
    OnSuccess = "getForm('" + Url.Action("ListEvents", "Event", null) + "','divList')"
}, new { id = "idformCreate" }))
{
    @Html.ValidationSummary(false, "Error on creation. Please retry after corrections.")
    <p>@Html.ValidationMessage("_FORM")</p>
    <div class="validation-summary-errors">
        <span></span>
        <ul>
        </ul>
    </div>
    <fieldset style="width: 800px; line-height: 1.4em;">
        <legend>Add an event</legend>
        <table style="width: 100%; padding-bottom: 0; padding-top: 0; border: 0;">
            <tr>
                <td style="width: 90px; border: 0;">
                    @Html.LabelFor(model => model.Event.event_date)
                </td>
                <td style="width: 200px; border: 0;">
                    @Html.EditorFor(model => model.Event.event_date, new { @class = "date" })
                    @Html.ValidationMessageFor(model => model.Event.event_date, "*")
                    @Html.HiddenFor(model => model.Event.client_ID)
                </td>
            </tr>
            <tr>
                <td style="width: 80px; border: 0; text-align: right;">
                    @Html.LabelFor(model => model.Event.event_place)
                </td>
                <td style="width: 120px; border: 0;">
                    @Html.DropDownList("Event.event_place", Model.PlacesList, "Where?", new { @style = "width: 100px;" })
                    @Html.ValidationMessageFor(model => model.Event.event_place, "")
                </td>
            </tr>
            <tr>
                <td style="width: 90px; border: 0;">
                    @Html.LabelFor(model => model.Event.event_description)
                </td>
                <td style="width: 600px; border: 0;" colspan="5">
                    @Html.TextAreaFor(model => model.Event.event_description, new { @class = "input_txt_nofloat", @style = "width:590px" })
                    @Html.ValidationMessageFor(model => model.Event.event_description, "*")
                </td>
            </tr>
            <tr style="height: 64px;">
                <td colspan="2" style="text-align: center;">
                    <br />
                    <br />
                    <input type="submit" value="Save" class="submit" style="width: 280px" />
                 </td>
            </tr>
        </table>
    </fieldset>
}
  • 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-31T21:16:35+00:00Added an answer on May 31, 2026 at 9:16 pm

    Here is the answer: (with a great thanks for BrockAllen)

    If you are doing your own client-side validation then you should
    remove jquery.validate.unobtrusive.min.js. This is MVC’s client side
    validation code and they will conflict if both are using
    jquery.validate.

    Hopefully, this will help other people too.

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

Sidebar

Related Questions

I have a View in my MVC3 application which displays one of two pretty
I have 2 Views in my MVC3 application. One View creates a cookie via
I have a properly working ajax form in my MVC3 application except for one
I have the following dropdown list in an MVC3 application and the selected item
My application is in Asp.Net MVC3 coded in C#.Net. I have Views which contains
I have a Razor view in my asp.net MVC3 application with a dropdownlist like
I have an ASP.NET MVC3 application in C# and Razor. In the view MyView
MVC3 VB.NET Razor view Application... I have a view that uses a for each
My Problem: I have an MVC3 application where all views use a common master
I have basic client-side validation working in my MVC3 RC2 application, but I'm now

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.