unobtrusive-validation

How to use the jQuery validate plugin with strongly typed enumerations?

ⅰ亾dé卋堺 提交于 2019-12-13 07:32:31
问题 I am using a strongly typed view that lists an enumeration of objects, something like this: @model IEnumerable<Foo> <table> <tbody> @Html.EditorForModel() </tbody> </table> Let's say Foo has a simple numeric property that I want to validate on the client side: public class Foo { [Required] public int Bar { get; set; } } Now the editor template for this object looks like this: @model Foo <tr> <td>@Html.TextBoxFor(m => m.Bar)</td> </tr> This works fine, except that the default model binder

How to get unobtrusive validation on my JQueryUI element, (Combobox)?

痴心易碎 提交于 2019-12-13 06:30:30
问题 In ASP NET MVC, I had an @Html.DropDownList in which the validation for the field was working just fine. As I needed the field to be editable I decided to use the JQueryUI Combobox, but right now I'm not getting the unobtrusive validation until I submit the form. So when I pick a right value, the error message posted before doesn't go away. How can I make the unobtrusive validation work again on each Key Press on my JQueryUI Combobox? 回答1: The fields wasn't getting the validation, because the

Client-side custom annotation validation not working

折月煮酒 提交于 2019-12-13 04:47:02
问题 I am trying to get client-side validation working with custom annotations in an ASP.NET MVC app. Sorry for the somewhat lengthy post. Here is the custom attribute: public class CustomStringLengthAttribute : ValidationAttribute, IClientValidatable { public int MaxLength { get; private set; } public int MinLength { get; set; } public CustomStringLengthAttribute(int maxLength) : base(GetDefaultErrorMessage) { MaxLength = maxLength; } private static string GetDefaultErrorMessage() { return "Max

Global settings for jQuery valdiator method

放肆的年华 提交于 2019-12-13 04:03:37
问题 I am sorry for my simple question but I can't get it work . How I can make this jquery validator method to work globally . I have this code in my layout: jQuery.validator.methods.number = function (value, element) { return this.optional(element) || !isNaN(Globalize.parseFloat(value)); }; jQuery(document).ready(function () { jQuery(function () { Globalize.culture("ro-RO"); }); }); But this is not working in my partial views so to make this code to work I have to put this in all my partial

Manually validate textbox with jQuery unobtrusive validation asp.net MVC3

荒凉一梦 提交于 2019-12-13 00:55:10
问题 So I have a multi-step process that allows a user to retrieve a forgotten password. The steps are like so, with a different action for each step in my controller: Enter username and email Enter password question answer Email a recovery link to the user if all goes well I tried using one model for everything: public class AccountForgotPassword { [Required()] [DisplayName("Username")] public string UserName { get; set; } [Required()] public string Email { get; set; } [Required()] public string

How to make a field required without data annotation

喜欢而已 提交于 2019-12-12 22:06:41
问题 I am using the MvcContrib Grid to display a table on the page. I am using a custom column to produce a checkbox on the table so that the user can select multiple rows and submit the form. I don't want the form to submit unless at least one checkbox has been selected. I could easily write this Javascript myself to enforce the validation, but I wanted to know how I could fit it in with the unobtrusive library supplied with MVC3. I imagine I just need to set my inputs with the proper classes and

Using built in ASP.NET MVC Validation with a wizard approach

杀马特。学长 韩版系。学妹 提交于 2019-12-12 19:23:38
问题 I am using the JQuery Steps Plugin basic form example for my Wizard. In this example you will notice they are using JQuery Validate plugin which is the same plugin ASP.NET MVC uses automatically when submitting a form. I am trying to figure out how to validate just the form fields in the current step when the user clicks continue, but using ASP.NET MVC syntax since I want my data-annotations to still work. Here is what my ASP.NET MVC version of the basic form example looks like (Notice that I

Jquery validation does not validate numbers properly?

*爱你&永不变心* 提交于 2019-12-12 13:23:18
问题 I've got a problem with validation of numbers using jquery unobtrusive validation. The versions I'm using are: ASP.MVC 3. JQuery 1.9.1 JQuery UI 1.10.1 JQuery Validation 1.11.0 the input I'm trying to validate is : <input type="number" value="0" name="Data.time_between_loops.Planned.hour" id="Data_time_between_loops_Planned_hour" data-val-required="The hour field is required." data-val-range-min="0" data-val-range-max="23" data-val-range="The field hour must be between 0 and 23." data-val

Client validation does not work on dom manipulated elements?

醉酒当歌 提交于 2019-12-12 10:19:09
问题 I have a simple form with a select element and an input element. Depending on the value in the select element i might or might not need the input element validated. What i did is, i set the 'data-val' attribute on the input element to either 'true' or 'false' depending on what is selected in the select element. This part is working - i can inspect the value of the attribute in firebug and it does change according to the plan. Now, in order to have the jquery unobtrusive validation to notice

Why do custom Unobtrusive Validator methods have to be added before document.ready runs?

寵の児 提交于 2019-12-12 10:14:46
问题 I'm working on an MVC4 app and needed some specific validation on a particular form. So I followed (several) tutorials on how to do this. Starting with a custom attribute: public class CheckDuplicateElementNameAttribute : ValidationAttribute, IClientValidatable { // Server side check omitted public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { ModelClientValidationRule rule = new ModelClientValidationRule(); rule