MVC 4 client side validation not working

I had the same problem. It seems that the unobtrusive validation scripts were not loaded (see screenshot at the end). I fixed it by adding at the end of _Layout.cshtml @Scripts.Render(“~/bundles/jqueryval”) The end result: @Scripts.Render(“~/bundles/jquery”) @Scripts.Render(“~/bundles/jqueryval”) @RenderSection(“scripts”, required: false) Except for my pretty standard CRUD views everything is Visual studio project template defaults. Loaded scripts … Read more

jQuery Validate plugin, one out of two fields is required

Using the optional additional-methods.js file, there is a method called require_from_group that does exactly what you request. (You must use at least version 1.11.1 of the plugin in order to avoid a past bug.) rules: { mobile:{ require_from_group: [1, ‘.mygroup’] }, telephone:{ require_from_group: [1, ‘.mygroup’] } }, …. The 1 parameter is how many from … Read more

Conditional Validation in asp.net MVC4

ASP.NET MVC 3 uses jquery unobtrusive validation to perform client side validation. So you could either write a custom RequiredIf validation attribute or use the one provided in Mvc Foolproof Validation and then: public class MyViewModel { [RequiredIf(“IsFlagSet”, true)] [Remote(“ValidateHosFin”, “EditEncounter”)] [MinLength(6)] public string HospitalFinNumber { get; set; } public bool IsFlagSet { get; set; … Read more

Validating array inputs using jquery validation plugin

You have two problems: You aren’t selecting the form element properly. You’re looking for a form with id “voucherform” and your markup does not contain one. You probably want to change your selector to: $(“form[name=”voucherform”]”).validate({ … }); Brackets ([]) are not valid in JavaScript identifiers. This means that your script is not being parsed correctly. … Read more

Jquery validation not working with ckeditor

Finally i found the answer to my question… I changed the value of ignore property which by default holds :hidden value. as CKEDITOR hides the textarea jQuery validation doesn’t validate the element: ignore: [] Just i changed the validation script as follows.. $(document).ready(function(){ $(“#f3”).validate( { ignore: [], debug: false, rules: { cktext:{ required: function() { … Read more