unobtrusive-validation

ASP.NET MVC 3 unobtrusive validation and radio buttons

梦想与她 提交于 2019-11-27 01:39:58
问题 I'm trying to do required validation on a list of radio buttons to force the user to select an option to continue. The validation does work but it only outputs metadata on the first radio button and it only marks the first radio button with the class input-validation-error. Example: <p>@Html.RadioButtonFor(x => x.Choices, SomeEnum.OptionOne)</p> <p>@Html.RadioButtonFor(x => x.Choices, SomeEnum.OptionTwo)</p> Resulting HTML: <p><input class="input-validation-error" data-val="true" data-val

Revalidating a modified ViewModel within a controller method?

有些话、适合烂在心里 提交于 2019-11-27 00:50:15
问题 EDIT - We're using MVC4 Dev Preview.... I'm implementing an edit page for a FishingTrip class. FishingTrip contains a child collection of simple Crew objects (i.e. FishingTripID, CrewID, CrewPosition). I'm using Jarrett Meyer's approach to add, edit and delete from the Crew collection. I'm using unobtrusive validation to specify that the properties of Crew are all Required . My problem: when I logically-delete an item from the list (as per Jarrett's method), I don't want that item to be

jQuery unobtrusive validation ignores “cancel” class on submit button if used in Ajax form

时光毁灭记忆、已成空白 提交于 2019-11-26 23:16:49
问题 I am trying to implement optional client side validation using ASP.NET MVC 4, unobtrusive jQuery validation, unobtrusive ajax This works fine Following pictures show what I mean with optional client side validation: The only one field on my form is expected to contain email, so there is an email validator attached to it. Now we click on save. Because our text "name@doamin" is not a valid email the validation summary gets displayed. Together with validation summary we are unhiding "Save anyway

client-side validation trips on DataAnnotation Range attribute

本小妞迷上赌 提交于 2019-11-26 22:25:30
问题 I have the following code in my Model class: [Range(1, 100)] public decimal Price { get; set; } After recent upgrade (I assume) of jquery.validate to 1.11.0, I am getting an error even if I enter valid value. If I turn off client validation in web.config - works fine. All other attributes (StringLength, Required) work fine. Generated HTML is the following (line breaks added for clarity): <input class="text-box single-line" data-val="true" data-val-number="The field Price must be a number."

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

好久不见. 提交于 2019-11-26 21:56:53
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 condition) { this.condition = condition; this.propertyName = propertyName; //Added } protected override

Unobtrusive validation not working on dynamically-added partial view

谁说我不能喝 提交于 2019-11-26 21:43:17
I am currently facing a problem with validation after dynamically adding content. I have a view strongly typed to a model ( Order ). This Order can have many items. The model looks something like the following: public class Order { [Key] [HiddenInput] public int id { get; set; } [Display(Name = "Order Number")] public string number { get; set; } [Display(Name = "Order Date")] [DataType(DataType.Date)] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")] public DateTime date { get; set; } [Required(ErrorMessage = "Beneficiary is required.")] [Display(Name =

How to change 'data-val-number' message validation in MVC while it is generated by @Html helper

…衆ロ難τιáo~ 提交于 2019-11-26 21:41:42
Assume this model: Public Class Detail ... <DisplayName("Custom DisplayName")> <Required(ErrorMessage:="Custom ErrorMessage")> Public Property PercentChange As Integer ... end class and the view: @Html.TextBoxFor(Function(m) m.PercentChange) will proceed this html: <input data-val="true" data-val-number="The field 'Custom DisplayName' must be a number." data-val-required="Custom ErrorMessage" id="PercentChange" name="PercentChange" type="text" value="0" /> I want to customize the data-val-number error message which I guess has generated because PercentChange is an Integer . I was looking for

ASP.NET MVC implement custom validator use IClientValidatable

半世苍凉 提交于 2019-11-26 20:47:43
I ask similar question here but in this question I use another implementation, exactly this way the following codes show my implementations: Model: public class Department { public long Id { get; set; } [IsDateAfter("Date2", true, ErrorMessage = "O My")] public DateTime Date1 { get; set; } public DateTime Date2 { get; set; } public string Name1 { get; set; } public string Name2 { get; set; } } Custom Validator: public sealed class IsDateAfter : ValidationAttribute, IClientValidatable { private readonly string testedPropertyName; private readonly bool allowEqualDates; public IsDateAfter(string

How to add a 'submitHandler' function when using jQuery Unobtrusive Validation?

橙三吉。 提交于 2019-11-26 19:45:55
I'm validating a form using the new unobtrusive validation features in ASP.NET MVC 3. So there is no code that I have written to setup jQuery validate to start validating my form. Its all done by loading the jQuery.validate.unobtrusive.js library. Unfortunately I need to whack in a 'are you sure?' message box when the form is valid but before submitting. With jQuery validate you would add the option handleSubmit when initialising like so: $("#my_form").validate({ rules: { field1: "required", field1: {email: true }, field2: "required" }, submitHandler: function(form) { if(confirm('Are you sure?

client side validation with dynamically added field

血红的双手。 提交于 2019-11-26 19:38:11
问题 I am using jQuery's unobtrusive validation plugin in with ASP.NET MVC. Any fields that are rendered on the server are properly validated. However, if I dynamically add a field in the form using JavaScript, it is not validated even though it has the appropriate HTML5 data-* attributes. Can anyone guide me in right direction on how I can achieve this goal? 回答1: Simpler Answer: I am using MVC 4 and JQuery 1.8. I have made it to a modular function which accepts the jQuery object of the newly