unobtrusive-validation

MVC4 Validation with razor and twitter bootstrap

怎甘沉沦 提交于 2019-11-29 08:20:26
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? 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 The accepted answer needed modifications to work with Bootstrap 3. I have used the following with success with MVC 4 and Bootstrap 3. $(function () { // any

How to use Html.GetUnobtrusiveValidationAttributes()

雨燕双飞 提交于 2019-11-29 04:16:28
I am trying to work around the fact that when they wrote asp.net MVC 3 they forgot to include code to add the unobtrusive validation attributes to select lists and their "fix" for this is to include it in MVC 4, which is no bloody use to anyone using MVC 3. My proposed work around is to use Html.GetUnobtrusiveValidationAttributes() to add them myself, just like any other custom attributes, but i can't work out the correct syntax for calling the method. There are 2 overloads, one takes a string and the other takes a string and a ModelMetaData class. I understand the metadata param, I presume I

Group validation messages for multiple properties together into one message asp.net mvc

浪尽此生 提交于 2019-11-29 03:36:55
I have a view model that has year/month/day properties for someone's date of birth. All of these fields are required. Right now, if someone doesn't enter anything for the date of birth they get 3 separate error messages. What I want to do is somehow group those error messages together into 1 message that just says 'Date of birth is required'. So if 1 or more of those fields are blank, they will always just get the 1 validation message. I NEED this to work on client-side validation via jquery validate and unobtrusive validate. I know this is possible with the jquery validate plugin by looking

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

别说谁变了你拦得住时间么 提交于 2019-11-29 02:01:38
问题 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 package, and all dependent packages I removed before. The "Microsoft.jQuery.Unobtrusive.Validation" package breaks saying: Attempting to resolve dependency 'jQuery (≥ 1.8)'. Attempting to resolve dependency 'jQuery.Validation (≥ 1.8)'. Attempting to

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

喜夏-厌秋 提交于 2019-11-29 00:19:15
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"}) @Html.Telerik().DropDownList().Name("DobYear").BindTo((SelectList)ViewData["Years"]).HtmlAttributes(new

ASP.Net MVC 3 unobtrusive client validation does not work with drop down lists

人盡茶涼 提交于 2019-11-29 00:03:22
I have a simple drop down list, the first item in the list has an empty value. If I do not select anything in the list the client validation ignores it. I have that field set up as required on the model using annotation attributes. @Html.DropDownListFor(model => Model.CCPayment.State, UnitedStatesStates.StateSelectList) [Required(ErrorMessage = "State is Required.")] public string State { get { return _state; } set { _state = value; } } any ideas? am I missing something? It looks like a legitimate bug, here's the best workaround I've found in my search: http://forums.asp.net/t/1649193.aspx In

Trouble getting unobtrusive validation working with mvc 3 on jquery ajax post

我的梦境 提交于 2019-11-28 23:29:39
I have having a lot of trouble getting validation to work on MVC3. It works fine when I just load the page directly, but it does not validate when I use jquery AJAX POST: This form is loaded using $('#modal-dialog').load('/DartsMVC/Restaurant/Edit/13') , This is the rendered HTML: <form action="/DartsMVC/Restaurant/Edit/13" method="post"> <fieldset> <legend>Restaurant</legend> <input data-val="true" data-val-number="The field RestaurantID must be a number." data-val-required="The RestaurantID field is required." id="RestaurantID" name="RestaurantID" type="hidden" value="13"> <div class="editor

How to manually enable jQuery validation with ASP.NET MVC

会有一股神秘感。 提交于 2019-11-28 21:22:40
I'm struggling to understand some of the basics of jQuery validation as wired up with ASP.NET MVC. The short version of this question is: What magic am I missing that allows the code produced by @Html.EditorFor() to perform jQuery validation, but doesn't work I try to wire up my own jQuery validation using the exact same HTML? As a learning exercise (and because it mimics what I really want to do in my website) I created a new MVC 4 app in Visual Studio 2012. I added a view model: using System.ComponentModel.DataAnnotations; namespace ValidationTest.Models { public class MyViewModel {

Disable validation for an element with jQuery Unobtrusive Validation

会有一股神秘感。 提交于 2019-11-28 20:47:18
By some form generator a list of elements is rendered on a page and they all have validations on them. When I look in the HTML source, i see something like this: <input type="text" id="email" name="email" data-val-required="No valid email address!" data-val="true"> I need to somehow have a dynamic way to enable/disable the validation for such an element. I tried to enable/disable the data-val attribute, by setting it to false and then back to true . But it doesn't seem to be responding to that. The validation is always there! Anyone has any idea how I can enable/disable validations on certain

How to clear jquery validate errors

我只是一个虾纸丫 提交于 2019-11-28 20:45:48
I'm hijaxing an existing form and POSTing to the server. jQuery validate does most of the validation but if validation fails on the server we return the errors to the client as JSON. Below is the code that does that: <script type="text/javascript"> $(function () { $("form").submit(function (e) { var $form = $(this); var validator = $form.data("validator"); if (!validator || !$form.valid()) return; e.preventDefault(); $.ajax({ url: "@Url.Action("index")", type: "POST", data: $form.serialize(), statusCode: { 400: function(xhr, status, err) { var errors = $.parseJSON(err); validator.showErrors