unobtrusive-validation

Client side validation on button click before AJAX request

安稳与你 提交于 2019-12-12 08:53:41
问题 I'm using MVC 4 and I want to be able to validate a single row, from a collection of rows in a table, to ensure that the fields are entered correctly and pass validation. The Attributes are correctly applied on the model, for example: [Required] [MaxLength(50)] [MinLength(5)] public string Name {get; set;} Now, on the client side - how do I enable client side validation before calling an AJAX method? To add more complications - I have a button where you can dynamically add a row to the table,

Parse attributes from MvcHtmlString

China☆狼群 提交于 2019-12-12 07:03:20
问题 I need to be able to parse the attributes from an MvcHtmlString (the results of an HtmlHelper extension), so that I can update and add to them. For example, take this HTML element: <input type="text" id="Name" name="Name" data-val-required="First name is required.|Please provide a first name."> I need to take the value from data-val-required , split it into two attributes with the second value going into a new attribute: <input type="text" id="Name" name="Name" data-val-required="First name

MVC4 graphical validation for text box

非 Y 不嫁゛ 提交于 2019-12-12 04:45:02
问题 I got a problem in MVC4 validation.Currently, i use validationMessageFor for error message. It is not so beautiful so i want to change my validation. i want to do graphical validation. for example, i want to validate Email in Entry form. if the email is valid, my text box will look like the following. if email is wrong, i want to show the user to following. in MVC4, is it possible to do it? how should i design my text box to get according to the picture? how to add tick icon and cross icon in

Validate only ajax loaded partial view

故事扮演 提交于 2019-12-12 04:14:11
问题 I have a form with some controls. There is a button on the form which loads a partial view. Inside the partial view, there are two required field textboxes along with a button. And when its clicked, I need to display error messages only for textboxes which are inside the partial view, but not for the fields in the actual form. And when I click form's submit button, all error messages must show up. After partial view is loaded, I am re-initializing the validation plugin as below. $('#test')

Jquery Unobtrusive validation lost after implementing onSubmit event

半腔热情 提交于 2019-12-12 02:59:58
问题 I'm using ASP.NET MVC. My validation works well until I attached an event to the form's onSubmit event. This is how my form looks: @using (Html.BeginForm("Recover", "Auth", FormMethod.Post, new { Id = "RecForm", onSubmit = "return Events.Submit(this,event)" })) { @Html.TextBoxFor(model => model.Email) @Html.ValidationMessageFor(model => model.Email) <input type="submit" value="Recover" /> } The Javascript (works fine, just put it here so you can check if something in this is causing the

MVC Foolproof validation - Cannot read property 'value' of undefined

两盒软妹~` 提交于 2019-12-12 02:29:08
问题 I am using MVC Foolproof validation in my application. Scenario is I have a dropdownlist named CustomerType with the the following values Id Name 1 Student 2 Non-Employed 3 Employed 4 SelfEmployed and I have one more property in my viewmodel public string CompanyAddress{ get; set; } .My goal is to make CompanyAddress required if dropdownlist has values 3 or 4 I have tried the following [Required(ErrorMessage = "Please select status of the customer", AllowEmptyStrings = false)] public int?

ASP.NET MVC Custom validation for a List<string>

烈酒焚心 提交于 2019-12-12 02:26:44
问题 I am using ASP.NET MVC 5 and on the client side want to use JQuery unobtrusive validation. Following is my model: public class CompanyModel { public CompanyModel() { Employees = new List<EmployeeModel>(); } public int CompanyId{ get; set; } public List<EmployeeModel> Employees { get; set; } } public class EmployeeModel { public EmployeeModel() { Values = new List<string>(); } public string Id { get; set; } public string Name { get; set; } [RequiredIf("IsRequired", true, "Atleast one value is

jquery.validate does not seem to work with certain inputs where name value includes a dot i.e RegisterModel.Pssword

邮差的信 提交于 2019-12-12 01:45:38
问题 In my views if I use a model that just has scalar, basic properties i.e [RegisterModel] everything works fine. But if I use a view model type where one or more properties is set to another .net complex type, say [RegisterModelAndLogOnModel] then the generated HTML does not work properly with the jQuery validate plug-in. With jQuery 1.7.2 it always tells me the confirmation password does not match the password, in jQuery 1.8.2 it just plain refuses to work and errors. I have now pin pointed

ASP.NET Core Unobtrusive Client Side Validation Form onsubmit fires even on validation failure

社会主义新天地 提交于 2019-12-12 01:25:31
问题 Note: This is related to .NET Core v2.0. You may find related posts but they don't address the issue I'm facing. I'm applying Unobtrusive Client side validation with code as below: <form asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" onsubmit="showPleaseWait()" > <div asp-validation-summary="All" class="text-danger"></div> <div class="form-group"> <label asp-for="Username" class="control-label"></label> <input asp-for="Username" class="form-control" placeholder="Username" /> <span

How to create warning messages in FluentValidation

本小妞迷上赌 提交于 2019-12-11 13:22:41
问题 I would like to add style to the validation messages based on enum type. FluentValidation offers possibility to add custom state for messages by using WithState method. Depending on which enum is used it would add a class for that message in HTML, so later I could add styling to it. Model validator class: public class SampleModelValidator : AbstractValidator<SampleModelValidator> { public SampleModelValidator() { RuleFor(o => o.Age)).NotEmpty() // Using custom state here .WithState(o =>