unobtrusive-validation

MVC : How to enable client side validation on hidden fields

北慕城南 提交于 2019-12-20 17:24:33
问题 @Scripts <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")"></script> <script src="@Url.Content("~/Scripts/jquery.validate.js")"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script> @View @using (Html.BeginForm("TestModelState", "RandD", FormMethod.Post, new {id="form123" })) { @Html.TextBoxFor(x => x.htmlText, new { style="display:none"})<br /> @Html.ValidationMessageFor(x => x.htmlText) <div> @Html.TextBoxFor(x => x.Uprop1)<br /> @Html

Add error message to @Html.ValidationSummary

ε祈祈猫儿з 提交于 2019-12-20 09:48:49
问题 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 validation that fires when the user hits the Submit button. (The validation looks across a number of form elements to make sure that the proper set of them have been checked, etc., so it's not as simple as just creating a new custom validator for a

Client form validation not working with modal dialog in MVC

北慕城南 提交于 2019-12-20 09:47:11
问题 I am changing a create form to become a modal dialog and jquery Unobtrusive validation stops working and don't know how to fix it. Index.cshtml has a link to trigger a modal dialog. <a href="#" id="createCustomer">Create</a> @section scripts{ <script type="text/javascript"> $('#createCustomer').on('click', function () { $.get('/Customer/Create', function (data) { $('#modalContainer').html(data); $('#myModal').modal({}); }); }); Create.cshtml is a partial view. @model Demo.Web.Models

ASP.Net MVC: How to supress jquery unobtrusive client side validation message based on condition

旧城冷巷雨未停 提交于 2019-12-20 07:14:07
问题 see my code first. View and view model public class SampleViewModel { [Display(Name = "Products")] public List<Product> Products { set; get; } [Required(ErrorMessage = "Select Male or Female")] public string Gender { get; set; } } public class Product { public int ID { set; get; } public string Name { set; get; } } controller code public ActionResult Index() { var SampleVM = new SampleViewModel(); SampleVM.Products = new List<Product> { new Product{ ID=1, Name="IPhone" }, new Product{ ID=2,

Client side validation not working

旧时模样 提交于 2019-12-20 06:31:19
问题 I implemented client side validation i.e, Required attributes specified in Model and HTML . ValidationMesssage For in .cshtml and referenced the JQuery validator and was working fine when I click on save button . But when I implement onClick event of button an ajax call, the validation seems to be not working. I tried using IsValid but no luck. Please find the below code. Controller [HttpPost] public ActionResult AddClient(ClientModel clientData) { var clientObj = new Metadata.Client.Service

RequireJS with jQuery Validation

ぐ巨炮叔叔 提交于 2019-12-20 02:37:13
问题 I'm trying to use RequireJS to add the references to my jQuery validation script files. I have 3 script files instead of the usual 1: jquery.validate - The jquery validation library jquery.validate.unobtrusive - This adds unobtrusive validation to the jquery validation library (so you can use data attributes and it automatic wires them up). This depends on jquery.validate jquery.validate.custom - This add my own custom unobtrusive validation methods and depends on jquery.validate.unobtrusive

show div if unobtrusive validation was invalid and hide it if Valid in MVC 3

◇◆丶佛笑我妖孽 提交于 2019-12-19 03:39:10
问题 This is a part of my Edit view: <dt> @Html.LabelFor(model => model.MainModel.StartDate) </dt> <dd> @Html.TextBoxFor(model => model.MainModel.StartDate) @Html.ValidationMessageFor(model => model.MainModel.StartDate) <div class="targetDiv"> My content </div> </dd> So as all of you know when StartDate field in my model not valid unobtrusive show the error message and if valid hide it. Now I want to add another action to this process. I need if StartDate value is Invalid show "targetDiv" div and

jQuery.Validation.Unobtrusive client side validation only works when scripts are on view page

我是研究僧i 提交于 2019-12-19 02:19:46
问题 I have an ASP.NET MVC 4 App that uses the jQuery.validation.js plugin and MVC's jQuery.validation.unobtrusive.js . I use data annotations on my view model to validate a textbox's input to be an integer. This (nested) view is loaded within a parent view using... <% Html.RenderPartial("New"); %> One the first inital page load, client side validation works. But any reloading of the nested view with an ajax call, client side validation no longer works. Why is that? Update : (Code example from

asp.net mvc client side validation not working?

五迷三道 提交于 2019-12-18 19:05:29
问题 For some reason my client side validation does not seem to be working: Here is my html: @using (Html.BeginForm("Create", "Home", FormMethod.Post)) { <hr /> @Html.ValidationSummary(true) <hr /> <p> <label>Select Client_ID: </label> <span class="field"> <select name="clientId" id="clientId"> @foreach (var item in Model.ClientId) { <option value="@item">@item</option> } </select> </span> </p> <p> <label>@Html.LabelFor(model => model.UserModel.name)</label> <span class="field"> @Html.EditorFor

mvc4 url validation

左心房为你撑大大i 提交于 2019-12-18 13:59:12
问题 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 url")] [DisplayName("Website")] public string web { get; set; } in the view, I have this @Html.EditorFor(model => model.web, new { AutoCompleteType = "Disabled", autocomplete = "off" }) now the problem lies in how the input text for this field is validated