unobtrusive-validation

Unobtrusive validation doesn't work with Ajax.BeginForm

China☆狼群 提交于 2019-11-28 17:28:32
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 Model1 @using (Ajax.BeginForm("Action1","Controller",null,new AjaxOption(){ onSuccess = "alert('=)')"},null) { <intput type="submit" value="Save" /> } Model2 model2 = new Model2(); @Html.EditorFor(m=>model2) **In Model2 view i have. ** @model Model2 @using (Ajax.BeginForm("AddStreet","Controller",new AjaxOption(){onSuccess = "alert('=)'")},option

jQuery Validate SubmitHandler with Ajax Submission Not being hit

自作多情 提交于 2019-11-28 13:17:59
问题 On my view I want to submit the form to the controller using ajax. I have this: @section scripts{ @Scripts.Render("~/bundles/jqueryval") <script> $(document).ready(function() { // Mask $("#Teu_Rate").mask("####.##", { reverse: true }); $("#Mcsap_Rate").mask("####.##", { reverse: true }); // Submission var redirectUrl = '@Url.Action("Index", "tblPersonnels")'; var settings = {}; settings.baseUri = '@Request.ApplicationPath'; var infoGetUrl = ""; if (settings.baseUri === "/Scalehouse") {

Unobtrusive validation of collection

自古美人都是妖i 提交于 2019-11-28 12:54:11
问题 My model contains a collection: public ICollection<int> ChildAges { get; set; } This is a dynamic list of ages that can be added to, this is all controlled via JQuery. giving me <select name="ChildAges">...</select> <select name="ChildAges">...</select> <select name="ChildAges">...</select> etc... If I add the standard Required attribute the validation returns true if any one value in the collection is set. How can I validate that all ChildAges in the form are set? 回答1: I created a new custom

custom validator MVC + validation client side

巧了我就是萌 提交于 2019-11-28 11:17:05
问题 I create a custom validateur in MVC 4: public class FirstNameValidator : ValidationAttribute { private IRegistrationConfiguration _registrationConfiguration; public string Category { get; set; } public bool IsLocal { get; set; } public FirstNameValidator() { _registrationConfiguration = DependencyResolver.Current.GetService<IRegistrationConfiguration>(); } public FirstNameValidator(IRegistrationConfiguration registrationConfiguration) { _registrationConfiguration = registrationConfiguration;

mvc clientside validation for nested (collection) properties

妖精的绣舞 提交于 2019-11-28 10:20:36
I'm using asp.net mvc 3 with jquery unobtrusive validation. I recently changed from standard DataAnnotations to FluentValidation and it works great. My primary reason for picking up FluentValidation was the need to validate nested properties on my viewmodel (but i found there are other cool reasons for using it) that kinda looks like this (don't mind accessors this is pseudo): class Vm { string Prop; string AnotherProp; IEnumerable<ElementsVm> Elements; } class ElementsVm { bool Required; string Id; string Title; string Value; } Using FluentValidation I make a validator for Vm and for

Model inheritance possible when using strongly-typed view in MVC3?

空扰寡人 提交于 2019-11-28 10:07:11
I have the following setup in my model: namespace QuickTest.Models { public class Person { [Required] [Display(Name = "Full name")] public string FullName { get; set; } [Display(Name = "Address Line 1")] public virtual string Address1 { get; set; } } public class Sender : Person { [Required] public override string Address1 { get; set; } } public class Receiver : Person { } } and in my view: @model QuickTest.Models.Person @{ ViewBag.Title = "Edit"; } <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery

ASP.NET MVC 3: Generate unobtrusive validation when BeginForm is on the layout

本小妞迷上赌 提交于 2019-11-28 08:45:27
I just realized that when I place a form tag on my layout page, surrounding the RenderBody section, the unobtrusive validation is not being generated. Something like this: @using (Html.BeginForm()) { <input type="submit" value="save" /> <div> @RenderBody() </div> } As you might have guessed I want to generate buttons over my content. Is this the correct unobtrusive's behavior? BTW, If I place the form inside a particular page, everything works like a charm: the data-val* attributes are well generated. I'll appreciate your valuable help. best regards Rodrigo You could apply a grotesque hack

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

南楼画角 提交于 2019-11-28 07:15:00
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 submit button Applying unobtrusive jquery validation to dynamic content in ASP.Net MVC What I've tried Given a various event listener, I've fired the following methods with no luck: $(selector).validate(); $(selector).valid(); $.validator.unobtrusive.parseDynamicContent(selector); $.validator.unobtrusive.parse($(selector)); Summary So I need client

ASP.NET MVC 3 unobtrusive validation and radio buttons

给你一囗甜甜゛ 提交于 2019-11-28 07:01:11
I'm trying to do required validation on a list of radio buttons to force the user to select an option to continue. The validation does work but it only outputs metadata on the first radio button and it only marks the first radio button with the class input-validation-error. Example: <p>@Html.RadioButtonFor(x => x.Choices, SomeEnum.OptionOne)</p> <p>@Html.RadioButtonFor(x => x.Choices, SomeEnum.OptionTwo)</p> Resulting HTML: <p><input class="input-validation-error" data-val="true" data-val-required="required text" type="radio" name="Choices" value="OptionOne" /></p> <p><input type="radio" name=

MVC3/4 Validating Hidden Fields

。_饼干妹妹 提交于 2019-11-28 06:03:55
问题 I have set up model validation for my form but validation doesn't seem to work at all. I don't suppose anybody can help. I've tried using the below work-around but that keeps pulling up an 'undefined' error in firebug. Example Work-Around Script: <script type="text/javascript"> $(document).ready(function () { $.validator.setDefaults({ ignore: [] }); }); </script> Example Text Field (Note: autocomplete text field with name of customer): @Html.TextBox("txtCustomer", null, new { @id =