unobtrusive-validation

When use IEnumerable in view client side validation is not working?

穿精又带淫゛_ 提交于 2019-12-25 05:10:06
问题 I am passing List from Model to view , so I specified in view like this IEnumerable. In this situation Client side validation is not firing View : @model IEnumerable<ShoppingCart.Models.ShoppingClass> @{ ViewBag.Title = "Display"; } <script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script> @Html.ValidationSummary(true) @using (Html.BeginForm()) { <table>

How to implement input masking with ASP.NET MVC

女生的网名这么多〃 提交于 2019-12-24 15:30:56
问题 I'm working on a form with ASP.NET MVC and am trying to figure out how best to implement input masking (e.g. for phone number or US zip code). Are there any commonly accepted approaches here for the data types I should use in my model. This question suggests to use a long for phone number and using a DisplayFormat attribute on the model field but it seems to conflict with validation. I don't really mind converting from one type in my view model to another type in my data models, but would

jQuery custom unobstrusive validator not working properly

戏子无情 提交于 2019-12-24 07:12:38
问题 I have written a custom jQuery unobstrusive validation rule which looks like this: <script> $.validator.addMethod("emailvalidate", function (value, element) { { var isSuccess; $.post("/Front/CheckEmail", { email: value }).done(function (data) { console.log("called"); isSuccess = data === "true" ? true : false }); console.log(isSuccess); return isSuccess; }}); $.validator.unobtrusive.adapters.add("emailvalidate", function (options) { options.rules["emailvalidate"] = true; if (options.message)

Which Data Annotation attribute creates this validation attribute?

六月ゝ 毕业季﹏ 提交于 2019-12-24 01:53:08
问题 Presuming we have a model like so: public class TheViewModel { public string DateTime? Image_Date { get; set; } } And it is added to a Razor view like so: Html.TextBoxFor(model => model.Image_Date) Then the following is rendered in the browser: <input data-val="true" data-val-date="The field Image_Date must be a date." id="Image_Date" name="Image_Date" type="text" value="" /> The attribute data-val-date is what I'm interested in. It's plainly being injected in by MVC's "unobtrusive" jQuery

Client side validation not working with reused and nested complex property

给你一囗甜甜゛ 提交于 2019-12-23 16:01:36
问题 I have an asp.net MVC 5 application in which I tried to re-use a nested complex view model class in different places in an .cshtml file. The reused complex view model is named as SchoolPersonViewModel that has many properties, and the Phone and Email properties are validated like "If Phone is not provided, then Email must be provided. If Phone is provided, then Email is optional input". I wrote a custom server and client side validation but it works with server side. But the client side

ASP.NET MVC [RegularExpression] Attribute Not Functioning on Entire String Match

筅森魡賤 提交于 2019-12-23 11:52:37
问题 I can't seem to find a similar topic on Stack Overflow regarding this, so here goes: Why is it when I specify against my ASP.NET MVC view model class the following definition: [Required] [RegularExpression(@"\A\d{3,4}\Z", ErrorMessage = "The security code (CVN) must be between 3 - 4 digits long.")] [Display(Name = "Card Security Code (CVN)")] public string CardCVN { get; set; } That on my unobtrusive client side validation test the regular expression cannot be validated? (and subsequently

jQuery unobtrusive custom adapter and method in jsFiddle

≡放荡痞女 提交于 2019-12-22 10:22:47
问题 I cannot make this jsFiddle work but it works in the browser: http://jsfiddle.net/vtortola/jYq2X/ I am trying to add a new custom rule to compare two fields. The custom adapter works, it is being called and setting the options. But the custom method is never called. I am executing this JS on DOM ready: $.validator.addMethod("customequal-method", function (val, el, p) { var $other = $(el).closest('form').find('input[name=' + p.other + ']'); return $other.length && $other.val() == val; }); $

Client-side validation of input type date does not work

喜你入骨 提交于 2019-12-22 05:08:10
问题 I have a form containing a date and datetime field: @Html.TextBoxFor(model => model.A, new { @type = "datetime" }) @Html.TextBoxFor(model => model.B, new { @type = "date" }) Model: public class TestModel { [DataType(DataType.Date)] public DateTime A {get;set;} [DataType(DataType.Date)] public DateTime B {get;set;} } By using these input types an iPad shows nice date(time) pickers. The fields are validated using client-side validation. For the datetime field ( A ) it works, but the date field

jQuery Validation - form.valid() always returning true

☆樱花仙子☆ 提交于 2019-12-21 11:59:07
问题 I have a situation when I try to check if a form is valid, but form.valid() always returns true. But if I try to validate the individual control, it returns false. This is my form: <div class="profilestagsedit"> @using (Html.BeginForm("", "", FormMethod.Post, new { id = "tagsform" })) { @Html.ValidationMessageFor(x => x.EditTagsText) @Html.TextBoxFor(p => p.EditTagsText, new { @id = "txtprofileedittags" }) } </div> This is my viewmodel: [Required(AllowEmptyStrings = false, ErrorMessage =

ASP.NET MVC 3 unobtrusive validation, submit and TinyMCE

两盒软妹~` 提交于 2019-12-20 20:46:20
问题 We have an in-house developed file/image/document manager plugin for TinyMCE that is still being ported over to jQuery. In the mean time, some of our projects that rely on having these features need to use the Prototype-based version of TinyMCE & jQuery.noConflict(). This works fine however with unobtrusive validation in ASP.NET MVC 3 the validation on submit happens before the TinyMCE callback to copy the TinyMCE'ed contents to the form field is triggered. Is it possible to hook into a pre