unobtrusive-validation

unobtrusive validation not working with dynamic content

北战南征 提交于 2019-11-26 19:33:24
I'm having problems trying to get the unobtrusive jquery validation to work with a partial view that is loaded dynamically through an AJAX call. I've been spending days trying to get this code to work with no luck. Here's the View: @model MvcApplication2.Models.test @using (Html.BeginForm()) { @Html.ValidationSummary(true); <div id="res"></div> <input id="submit" type="submit" value="submit" /> } The Partial View: @model MvcApplication2.Models.test @Html.TextAreaFor(m => m.MyProperty); @Html.ValidationMessageFor(m => m.MyProperty); <script type="text/javascript" > $.validator.unobtrusive.parse

MVC 4 client side validation not working

岁酱吖の 提交于 2019-11-26 19:31:01
问题 Can anyone tell me why client side validation is not working in my MVC 4 application. _layout.schtml @Scripts.Render("~/bundles/jquery") @RenderSection("scripts", required: false) In my web.config I have: <appSettings> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> In my login.cshtml page I have: @using (Html.BeginForm()) { <div class="formscontent"> <ol> <li> @Html.LabelFor(x => x.AgreementNumber) <br /> @Html

RequiredAttribute with AllowEmptyString=true in ASP.NET MVC 3 unobtrusive validation

蹲街弑〆低调 提交于 2019-11-26 19:25:01
问题 If i have [Required(AllowEmptyStrings = true)] declaration in my view model the validation is always triggered on empty inputs. I found the article which explains why it happens. Do you know if there is a fix available? If not, how do you handle it? 回答1: Note: I'm assuming you have AllowEmptyStrings = true because you're also using your view model outside of a web scenario; otherwise it doesn't seem like there's much of a point to having a Required attribute that allows empty strings in a web

MVC3 Unobtrusive Validation Not Working after Ajax Call

北城以北 提交于 2019-11-26 18:54:11
问题 Ok, here is the deal, I have seen a few posts on SO relating to this issue, but nothing is working for me. Basically, I have select drop downs that are being loaded from partial views, I am trying to filter contents of each subsequent drop down, based on the previously selected drop down. If I just put the call to the partial view in the div containers, and load the page, the validation from data annotations works fine, primarily Required attribute . However, if I try to load the same partial

MVC unobtrusive validation on checkbox not working

时间秒杀一切 提交于 2019-11-26 18:49:50
问题 I'm trying to implement the code as mentioned in this post. In other words I'm trying to implement unobtrusive validation on a terms and conditions checkbox. If the user hasn't selected the checkbox, then the input should be marked as invalid. This is the server side Validator code, I've added: /// <summary> /// Validation attribute that demands that a boolean value must be true. /// </summary> [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] public class

Unobtrusive validation in Chrome won't validate with dd/mm/yyyy

社会主义新天地 提交于 2019-11-26 17:10:59
I'm trying to use the simplest possible scenario using a date picker in different browsers. I suspect I'm doing something very simple the wrong way but after lots of searching around I still haven't found a solution. Below is some sample code that represents what I'm attempting. If I use Chrome (v12.0.742.122) and pick a date from the picker like 13/08/2011 the jQuery validation logic will not allow the page to submit even though I've explicitly specified the format as 'dd/mm/yy'. If I change the format to 'dd/M/yy' and choose a date like 13/Aug/2011 it works in Chrome but then won't submit

Adding jQuery validator rules to dynamically created elements in ASP

痞子三分冷 提交于 2019-11-26 15:35:40
问题 I've got some dynamically inserted form fields on a page in an MVC3 project. Normally we would add the jQuery validation server-side, but in this case we can't (multiple fields in the UI generate the value for one hidden field - and this is what is submitted. We can't validate against a hidden field, so we must instead add UI-only validation for the fields the user can see) Once the fields are dynamically added to the page, I run the following code over the container: $container.find(".date")

Best Practices ViewModel Validation in ASP.NET MVC

假装没事ソ 提交于 2019-11-26 15:20:52
问题 I am using DataAnnotations to validate my ViewModel on client side with jquery.validate.unobtrusive and on server side in ASP.NET MVC application. Not so long time ago, I figured out that I can write validation like this: [Required(ErrorMessage = "{0} is required")] public string Name { get; set; } That way I can easily define some general strings in config or in resources and always use it in DataAnnotations . So it will be easier to change validation messages in my whole application in

Manually set unobtrusive validation error on a textbox

无人久伴 提交于 2019-11-26 13:44:40
问题 I'm doing something similar to the remote validation, except that I already make my calls manually via jquery and setup whatever I had to setup. Now my problem is, if I want to tell the validator that a particular textbox is not valid (and prevents the page from submitting, highlight the textbox, etc). How would I do this from code? @Html.LabelFor(m => Model.Slug) @Html.TextBoxFor(m => Model.Slug) <span id="UrlMsg" class="field-validation-error" style="display: none;"></span> if (error) { $('

client-side validation in custom validation attribute - asp.net mvc 4

感情迁移 提交于 2019-11-26 08:08:18
问题 I have followed some articles and tutorials over the internet in order to create a custom validation attribute that also supports client-side validation in an asp.net mvc 4 website. This is what i have until now: RequiredIfAttribute.cs [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] //Added public class RequiredIfAttribute : ValidationAttribute, IClientValidatable { private readonly string condition; private string propertyName; //Added public RequiredIfAttribute(string