unobtrusive-validation

MVC3 Unobtrusive Validation Extension; Terms and Conditions checkbox

做~自己de王妃 提交于 2019-12-11 01:14:37
问题 There are a few other posts I've seen about this: MVC unobtrusive validation on checkbox not working MVC3: make checkbox required via jQuery validate? But I've implemented them and can't quite figure out why my validation isn't working properly: Attribute: [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public sealed class MustBeTrueAttribute : ValidationAttribute, IClientValidatable { public override bool IsValid(object value) {

Trouble Attaching Call Back to Unobtrusive Validation Show Error

穿精又带淫゛_ 提交于 2019-12-11 00:04:28
问题 I'm having trouble attaching a call back to jquery unobtrusive validate. What I want to do is hide an informational message any time a field validation error is shown. They both take up the same area on the page. I can't figure out how to attach a callback to the show error method. I have one that works if you call validate but the error messages are shown before even change for the field is fired. Here is a jsfiddle demoing my problem. http://jsfiddle.net/K6NcF/4/ This is the callback that

Handling placeholders using unobtrusive validation

折月煮酒 提交于 2019-12-10 23:17:35
问题 I have a form that has placeholders for input fields. It uses html5 placeholder attribute and javascript placeholder fallback. I use unobtrusive validation like so: [DisplayName("")] [Required(ErrorMessage = "Please enter a name")] [StringLength(maximumLength: 20, MinimumLength = 1, ErrorMessage = "max length is 20 chars.")] public string UserName { get; set; } [DisplayName("")] [Required(ErrorMessage = "Please enter a comment.")] [StringLength(maximumLength: 350, MinimumLength = 1,

MVC DropDownListFor and StringLength Attribute Not Playing Well together

不羁的心 提交于 2019-12-10 14:56:55
问题 My stringlength validation always fails on dropdownlists with a string value. Here is my model: [Required(ErrorMessage = "Required")] [StringLength(2, MinimumLength = 2)] [Display(Name = "Home Address State")] public string HomeAddressState { get; set; } Here is my view: @Html.DropDownListFor(model => model.HomeAddressState, new SelectList(ViewBag.States, "Value", "Text"), string.Empty) @Html.ValidationMessageFor(model => model.HomeAddressState) Here is the html output: <select data-val="true

Disable System.CompositionModel.DataAnnotation from generating db scema instead use it just for unobstrusive jquery validation

扶醉桌前 提交于 2019-12-10 12:24:35
问题 I want to use System.CompositionModel.DataAnnotation for building Model but it should not affect database schema for example if I am using Required then it should not make that column as not nullable in Database. The reason I want to use Data annotation is for MVC 4 JQuery Unobstrusive validation. As of Now I have applied validation by using @Html.TextBoxFor(model => model.BookingRequest.Email, new { data_val = "true", data_val_required = "Please provide Special Notes" }) I think this is not

ASP.NET MVC 4 Unobtrusive validation broken on complex models

安稳与你 提交于 2019-12-10 11:49:18
问题 Alright, so I have a model that looks like: public class CustomerViewModel { public string Password { get; set; } } public class CustomerAddViewModel { public CustomerViewModel Customer { get; set; } [System.ComponentModel.DataAnnotations.Compare("Customer.Password", ErrorMessage = "The confirm password should match")] public string ConfirmPassword { get; set; } } I get the error message "Could not find a property named Customer.Password" on validation. I found this SO Question, but it doesn

Custom clientside validation for required at least one in array

两盒软妹~` 提交于 2019-12-10 11:06:14
问题 I have the following custom attribute that is used to validate if an array has had a value submitted: [AttributeUsage(AttributeTargets.Property, AllowMultiple = true, Inherited = true)] public sealed class RequiredArrayAttribute : RequiredAttribute, IClientValidatable { public RequiredArrayAttribute() : base() { } public override bool IsValid(object value) { var list = (IList)value; if (list != null && list.Count > 0) { return true; } return false; } public IEnumerable

Create a complex type model validation attribute with server and client validation

前提是你 提交于 2019-12-10 10:59:05
问题 I'm trying to create an attribute that can validate a complex type both on the server and client side. This attribute will be used for required and non required complex types such as the following Address Class public partial class AddressViewModel { [DisplayName("Address 1")] [MaxLength(100)] public virtual string Address1 { get; set; } [DisplayName("Address 2")] [MaxLength(100)] public virtual string Address2 { get; set; } [MaxLength(100)] public virtual string City { get; set; } [MaxLength

Globally Override ASP.Net MVC Default Attribute Error Messages

帅比萌擦擦* 提交于 2019-12-10 07:41:47
问题 How can I use resources from a different assembly to override the default attribute error messages in my MVC5 application? My website is namespaced: Company.Web My resources assembly is namespaced: Company.Web.Resources I can easily localize attribute error messages individually using: [Required(ErrorMessageResourceName = "PropertyValueRequired", ErrorMessageResourceType = typeof(Company.Web.Resources.Messages))] However, since our error message is always "Required", I'd simply like to put

mvc3 jquery unobtrusive validation locale decimal field

旧街凉风 提交于 2019-12-10 04:34:20
问题 I'm working on localized mvc3 web application using unobtrusive validation. In web.config I've got : <globalization culture="pl-PL" uiCulture="pl" /> Jquery 1.4.4 and jquery validation 1.6 is in use. Problem is with decimal number separator character. I can see that jquery validation is ignoring the culture and is expecting a dot character to always be the decimal separator. I need to use comma instead. I think it's the same in German language for example. I created my own methods_pl.js file