Questions tagged [unobtrusive-validation]

Unobtrusive Validation refers to a jQuery plugin created by Microsoft used in conjunction with the jQuery Validate plugin. It is shipped with ASP.NET MVC 3.

Unobtrusive Validation is a jQuery plugin written by Microsoft that acts as a support library for jQuery and the jQuery Validate plugin.

The script is shipped as part of ASP.NET MVC 3 and is included in new Visual Studio 2010 MVC 3 projects by default. It uses HTML5 data attributes (data-val-*) usually originating from DataAnnotation attributes on the view's model.

1239 questions
37
votes
4 answers

MVC3 Validation - Require One From Group

Given the following viewmodel: public class SomeViewModel { public bool IsA { get; set; } public bool IsB { get; set; } public bool IsC { get; set; } //... other properties } I wish to create a custom attribute that validates at least one…
Shawn
  • 1,871
  • 2
  • 21
  • 36
34
votes
4 answers

Best Practices ViewModel Validation in ASP.NET MVC

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 =…
33
votes
5 answers

Unobtrusive validation doesn't work with Ajax.BeginForm

I have View with Model1 where I put Ajax.BeginForm() and in this View i have PartialView with Model2 where i put Ajax.BeginForm(). So only in first form working unobtrusive validation. Why only in first form working validation? first View @model…
Oleksandr Fentsyk
  • 5,256
  • 5
  • 34
  • 41
32
votes
2 answers

.Net Mvc 3 Trigger (other than submit button) Unobtrusive Validation

What I would Like I would like to trigger client-side validation in my View with an event of my choice. It could be 'onblur' maybe another button but something other than the submit button. Relevant Links How to trigger validation without using a…
32
votes
2 answers

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

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…
30
votes
7 answers

Best approach for extending unobtrusive javascript in MVC3 to add a style to a div client side

I'm using html5/Razor/MVC3 leveraging the Bootstrap template from Twitter. I want to have form validation that looks slick like they've documented (http://twitter.github.com/bootstrap/#forms). So if we take a look at how the standard boiler-plate…
28
votes
3 answers

Adding jQuery validator rules to dynamically created elements in ASP

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…
Chris Barr
  • 29,851
  • 23
  • 95
  • 135
28
votes
2 answers

Add error message to @Html.ValidationSummary

I'm using standard MVC3 Razor views with unobtrusive Javascript validation, using @Html.ValidationSummary to show them at the top of the form. If the standard validations (things like [Required]) pass, I then run some very custom client-side…
Kras
  • 623
  • 2
  • 9
  • 13
28
votes
3 answers

Where can one download Microsoft jQuery Unobtrusive Validation without using NuGet

I'd like to download the latest version of Microsoft jQuery Unobtrusive Validation, however I don't like using NuGet since it is not possible for me to tell it where to install the packages within my project structure. Does Microsoft host these…
theycallmemorty
  • 12,515
  • 14
  • 51
  • 71
26
votes
2 answers

mvc4 url validation

I'm writing this question here after trying to find an answer for two days. basically here's what's going on. I have a property in the viewmodel as follows [Required(ErrorMessage = "Required Field")] [Url(ErrorMessage="Please enter a valid…
Amila
  • 3,711
  • 3
  • 26
  • 42
25
votes
6 answers

Integrating Twitter Bootstrap with Asp.net MVC 3 forms

I am using Asp.net MVC 3 and Twitter Bootstrap. What I want is to integrate both of them. The big problem for me is forms. I am using the HtmlHelper and it is a problem, when it comes to the validation, I want it to generate HTML like this:
24
votes
3 answers

Adding the "Microsoft.jQuery.Unobtrusive.Validation" package asks for jQuery 1.4.1?

In one of the projects I needed to reinstall the jQuery NuGet package (a MVC solution). There were also a "Microsoft.jQuery.Unobtrusive.Validation", that I should uninstall before removing the jQuery package. Now I try to (re)install the jQuery…
serhio
  • 28,010
  • 62
  • 221
  • 374
23
votes
6 answers

MVC unobtrusive validation on checkbox not working

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. …
22
votes
2 answers

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

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
2
3
82 83