Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC2/Jquery validation issues
    primarykey
    data
    text
    <p>I have read the following: <a href="http://weblogs.asp.net/imranbaloch/archive/2010/08/23/asp-net-mvc-jquery-validation-and-validationsummary.aspx" rel="nofollow">http://weblogs.asp.net/imranbaloch/archive/2010/08/23/asp-net-mvc-jquery-validation-and-validationsummary.aspx</a></p> <p><a href="http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx" rel="nofollow">http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx</a></p> <p>And still can't get the jQuery validation to work with MVC2. I can get non jQuery working but when i swap out the JS files it doesn't work. It's going on day 3 and I'm totally stuck at this point. So here is what I have. I appreciate your help.</p> <p>Site.Master</p> <pre><code> &lt;script src="&lt;%= this.ResolveClientUrl("~/Resources/js/jquery-1.4.1.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="&lt;%= this.ResolveClientUrl("~/Resources/js/jquery.validate.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="&lt;%= this.ResolveClientUrl("~/Resources/js/MicrosoftMvcJqueryValidation.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="&lt;%= this.ResolveClientUrl("~/Resources/js/ourJS--VERSION--.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="&lt;%= this.ResolveClientUrl("~/Resources/js/json2.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt; &lt;link href="../../Resources/css/ourCSS--VERSION--.css" rel="stylesheet" type="text/css" /&gt; </code></pre> <p>ViewModel:</p> <pre><code>namespace OurNamespace { [ExcludeFromCodeCoverage] public class OurDataModelView : PersistedDataModelView { public OurModelView () : base() { ID = -1; StartDate = DateTime.MinValue; EndDate = DateTime.MinValue; Description = string.Empty; Deleted = false; } [DisplayFormat(DataFormatString = "{0:MM/yyyy}")] public DateTime? StartDate { get; set; } [DisplayFormat(DataFormatString = "{0:MM/yyyy}")] public DateTime? EndDate { get; set; } [Required(ErrorMessage="Description is required.")] [StringLength(250000, ErrorMessage = "A maximum of 250000 characters are allowed")] public string Description { get; set; } public int? ID { get; set; } public bool Deleted { get; set; } } } </code></pre> <p>ASPX page</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;dynamic&gt;" %&gt; ... &lt;% Html.RenderAction(WebConstants.ACTION_DISPLAY_HEADER, WebConstants.CONTROLLER, new { id = ViewData["ID"] }); %&gt; ... </code></pre> <p>our partial view that validation is done on:</p> <pre><code> &lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;OurNameSpace.OurDataModelView&gt;" %&gt; ... &lt;% Html.EnableClientValidation(); %&gt; &lt;% using (Html.BeginForm("", "", FormMethod.Post , new { id = "HeaderForm", onSubmit="return false;"})) { %&gt; &lt;%: Html.ValidationSummary(false, "validation failed") %&gt; &lt;%: Html.HiddenFor(model =&gt; model.ID) %&gt; &lt;div class="form-row"&gt; &lt;div class="form-label"&gt;Description&lt;/div&gt; &lt;div class="form-element"&gt;&lt;%: Html.TextAreaFor(model =&gt; model.Description)%&gt;&lt;/div&gt; &lt;div&gt;&lt;%= Html.ValidationMessageFor(model =&gt; model.Description) %&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="buttons"&gt; &lt;input id="Save" type="submit" class="save-button" value="" /&gt; &lt;div id="Cancel" class="cancel-button"&gt;&lt;/div&gt; &lt;/div&gt; &lt;% } %&gt; ... </code></pre> <p><em>*</em>*SO by doesn't work here is what I do see. on view source I see:</p> <pre><code>//&lt;![CDATA[ if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; } window.mvcClientValidationMetadata.push({"Fields":[{"FieldName":"Description","ReplaceValidationMessageContents":true,"ValidationMessageId":"Description_validationMessage","ValidationRules":[{"ErrorMessage":"A maximum of 250000 characters are allowed","ValidationParameters":{"minimumLength":0,"maximumLength":250000},"ValidationType":"stringLength"},{"ErrorMessage":"Description is required.","ValidationParameters":{},"ValidationType":"required"}]}],"FormId":"HeaderForm","ReplaceValidationSummary":true,"ValidationSummaryId":"validationSummary"}); //]]&gt; </code></pre> <p>However, client side validation is not appearing. I click on the textarea type in a char and delete it unfocus from the element and nothing happens. Any ideas for debugging this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload