unobtrusive-validation

Integrating Twitter Bootstrap with Asp.net MVC 3 forms

和自甴很熟 提交于 2019-12-02 16:40:43
I am using Asp.net MVC 3 and Twitter Bootstrap. What I want is to integrate both of them. The big problem for me is forms. I am using the HtmlHelper and it is a problem, when it comes to the validation, I want it to generate HTML like this: <div class="control-group error"> <label for="field" class="control-label">OMG this label is so awesome: </label> <div class="controls"> <input type="text" name="field" id="field" value="yeah" /> <span class="help-inline">Eventually some error :C</span> </div> </div> Here is my HtmlHelper code: @Html.LabelFor(x => x.Field) @Html.EditorFor(x => x.Field)

ASP.NET MVC 3 unobtrusive client-side validation with dynamic content

时光总嘲笑我的痴心妄想 提交于 2019-12-02 06:54:13
问题 I have enabled unobtrusive client side validation in my app, and I have (something similar) to this model: public class MyModel { [Required] public string Name { get; set; } [Range(0, 100)] public int? Age { get; set; } } I have the following /Home/Index view: @model MyModel @using (Html.BeginForm("Test", "Home")) { <div id="my-form"> @Html.Partial("Model") </div> <input type="submit" value="Go" /> } With the partial "Model": @model MyModel <div> @Html.LabelFor(x => x.Name) @Html.TextBoxFor(x

Unobtrusive validation not working after adding checkboxes to the form in mvc 4

时光毁灭记忆、已成空白 提交于 2019-12-02 03:36:35
问题 I want to make checkboxes optional, whether to be checked or not. But when I add a checkbox on my view it will make unobtrusive validation to be stopped. But when I remove the checkbox from my view, unobtrusive validations works fine. What's the problem ? I am adding checkbox like this: @Html.CheckBoxFor(model => model.features.safetyfeature.Airbag) All the model values are correct. 回答1: I had exactly this problem & posted a question here. Currently I don't have a solution to the problem, but

Unobtrusive validation not working after adding checkboxes to the form in mvc 4

天涯浪子 提交于 2019-12-01 22:45:59
I want to make checkboxes optional, whether to be checked or not. But when I add a checkbox on my view it will make unobtrusive validation to be stopped. But when I remove the checkbox from my view, unobtrusive validations works fine. What's the problem ? I am adding checkbox like this: @Html.CheckBoxFor(model => model.features.safetyfeature.Airbag) All the model values are correct. markpsmith I had exactly this problem & posted a question here . Currently I don't have a solution to the problem, but I did find a workaround. Instead of using Html.CheckBoxFor I used Html.CheckBox like so: @Html

RequireJS with jQuery Validation

一世执手 提交于 2019-12-01 21:15:08
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 I have setup the following configuration: require.config({ paths: { 'jquery': 'Scripts/jquery-1.8.3.min

Validate dropdown item does not occur more than once in a list of dropdown fields with the same id

廉价感情. 提交于 2019-12-01 20:53:30
I have a form where the user can add as many rows as needed. Each time they are expected to select a different option from the dropdown list provided. At the moment there is no validation to stop them selecting the same value multiple times. Each row is a "ResourceCount". The ViewModel has an IList of ResourceCountViewModel, so each row is being added as an item to the list. The ResourceCount view model consists of an "id" to store the dropdown value selected and a "quantity" for the number field. I can't think of a way to use the Compare annotation in this scenario. How can I implement

How can I customize the unobtrusive validation JQuery messages in ASP NET MVC?

拟墨画扇 提交于 2019-12-01 20:20:28
问题 I have a form, and when it does the unobtrusive validtaion I want it to show: This message: "Please enter a value. " Instead of this message: "This Field is required." I tried adding this at the end of my jquery.validate.unobtrusive.js file (function ($) { $.extend($.validator.messages, { required: "Please enter a value." }); }(jQuery)); But it's just not working. I also trying modifying directly the "messages" variable in jquery.validate.js file but it is not working either. Could you please

How can I customize the unobtrusive validation JQuery messages in ASP NET MVC?

隐身守侯 提交于 2019-12-01 18:07:00
I have a form, and when it does the unobtrusive validtaion I want it to show: This message: "Please enter a value. " Instead of this message: "This Field is required." I tried adding this at the end of my jquery.validate.unobtrusive.js file (function ($) { $.extend($.validator.messages, { required: "Please enter a value." }); }(jQuery)); But it's just not working. I also trying modifying directly the "messages" variable in jquery.validate.js file but it is not working either. Could you please tell me how can I get this done? hawkke If you're using the data annotation attributes and don't want

Fluent Validation in MVC: specify RuleSet for Client-Side validation

≯℡__Kan透↙ 提交于 2019-12-01 17:14:50
In my ASP.NET MVC 4 project I have validator for one of my view models, that contain rules definition for RuleSets. Edit ruleset used in Post action, when all client validation passed. Url and Email rule sets rules used in Edit ruleset (you can see it below) and in special ajax actions that validate only Email and only Url accordingly. My problem is that view doesn't know that it should use Edit rule set for client html attributes generation, and use default rule set, which is empty. How can I tell view to use Edit rule set for input attributes generation? Model: public class ShopInfoViewModel

Either Or Required Validation

僤鯓⒐⒋嵵緔 提交于 2019-12-01 16:58:28
I want to use ComponentModel DataAnnotations validate that at least one of two properties has a value. My model looks like this: public class FooModel { public string Bar1 { get; set; } public int Bar2 { get; set; } } Basically, I want to validate FooModel so that either Bar1 or Bar2 is required . In other words, you can enter one, or the other, or both, but you can't just leave them both empty. I would prefer that this worked both for server-side and unobtrusive client-side validation. EDIT: This may be a possible duplicate, as this looks similar to what I'm looking to do You would need to