unobtrusive-validation

Revalidating a modified ViewModel within a controller method?

我与影子孤独终老i 提交于 2019-11-28 05:12: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 validated. I have successfully tweaked the "removeRow" method on the client-side to disable unobtrusive

How to force form client-side validation in or before $.ajax()

谁都会走 提交于 2019-11-28 03:03:06
问题 I have a form and unobtrusive validations are enabled. By default in submit method client side validation gets triggered and (if you have any errors) the form looks like this: The validation happens even before any data gets sent to the server. Now this behavior doesn't work if you want to use $.ajax method. Client side validation doesn't work. You have to manually check all the fields in your javascript, losing all the beauty of DataAnnotations. Is there any better solution? I could've use

How to setup MVC 5 unobtrusive validation correctly when appending the form from an AJAX call?

大城市里の小女人 提交于 2019-11-28 03:01:46
问题 I have googeld about this issue and I have checked my web.config, bundleconfig and my layout which look like this: web.config: <appSettings> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> In my App_Start folder under "BundleConfig.cs": var jqueryBundle = new ScriptBundle("~/bundles/jquery"); jqueryBundle.Include("~/Scripts

MVC4 Validation with razor and twitter bootstrap

笑着哭i 提交于 2019-11-28 01:41:31
问题 I need to validate my input in MVC4 razor. The problem is, I want to use twitter bootstrap and then set the error message class for the top div as seen here: http://getbootstrap.com/css/#forms-control-states How can I change the parent div 's class? 回答1: Have you tried this script? http://blog.ijasoneverett.com/2013/05/asp-net-mvc-validation-with-twitters-bootstrap/ I use something similar for getting bootstrap and mvc validation to play nice 回答2: The accepted answer needed modifications to

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

一世执手 提交于 2019-11-28 00:12:12
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" button. This second button is a normal submit button just having class="cancel" . This instructs

Validation type names in unobtrusive client validation rules must be unique

ぐ巨炮叔叔 提交于 2019-11-27 21:50:53
Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required This is referring to the EmailAddress property, here: public class LoginModel { [Required] [DataType(DataType.EmailAddress)] [Display(Name = "Email")] [AdditionalMetadata("Style", "Wide")] public string EmailAddress { get; set; } [Required] [DataType(DataType.Password)] [Display(Name = "Password")] [AdditionalMetadata("Style", "Wide")] public string Password { get; set; } } I'm not using the same type of validation rule twice here. This works fine locally

How to validate a date using 3 dropdowns( day, month, year ) using jquery unobtrusive validation?

痴心易碎 提交于 2019-11-27 21:26:24
问题 I have a model to validate and the problem is the date of birth field. It must be composed of 3 dropdowns (day, month, year). <div id="dob-editor-field" class="model-field-editor"> @Html.LabelFor(m => m.DateOfBirth, new { @class = "label-div" }) @Html.Telerik().DropDownList().Name("DobDay").BindTo((SelectList)ViewData["Days"]).HtmlAttributes(new {id = "DobDaySel"}) @Html.Telerik().DropDownList().Name("DobMonth").BindTo((SelectList)ViewData["Months"]).HtmlAttributes(new { id = "DobMonthSel"})

Syntax error with parseJSON during unobtrusive validation

孤街浪徒 提交于 2019-11-27 20:37:35
My MVC app is generating the following HTML which causes a Javascript syntax error upon submission (I'm not typing anything into the two text boxes). Here's the generated HTML and the submit handler: <form action="/UrIntake/Save" id="UrIntakeForm" method="post"> <input data-val="true" data-val-length="The field LastName must be a string with a maximum length of 50." data-val-length-max="50" data-val-required="The LastName field is required." id="FormSubmitter_LastName" name="FormSubmitter.LastName" type="text" value="" /> <input data-val="true" data-val-length="The field FirstName must be a

mvc3 validate input 'not-equal-to'

有些话、适合烂在心里 提交于 2019-11-27 20:33:43
问题 My forms have inputs with default helper text that guides the user on what to enter (rather than using labels). This makes validation tricky because the input value is never null. How can I extend unobtrusive validation to handle this? The form shouldn't be valid if the Name input is equal to "Please enter your name..." I started reading Brad Wilson's blog post on validation adapters, but I'm not sure if this is the right way to go? I need to be able to validate against different default

MVC unobtrusive range validation of dynamic values

↘锁芯ラ 提交于 2019-11-27 19:28:53
I have a value on my model, that must fall within the range of two other values on my model. For example: public class RangeValidationSampleModel { int Value { get; set; } int MinValue { get; set; } int MaxValue { get; set; } } Of course, I can't pass these Min/MaxValues into my DataAnnotations attributes, as they have to be constant values. I'm sure I need to build my own validation attribute, but I haven't done this much and can't wrap my mind around how it should work. I've searched for about an hour, and have seen all sorts of solutions for building custom validation, but can't find