asp.net-mvc-validation

Validation of properties that require the values of other properties

六眼飞鱼酱① 提交于 2021-01-29 03:36:56
问题 So I have checked out this answer ASP:NET MVC 4 dynamic validation of a property depending of the current value of another property and it does not cover the issue I am having. I am using server side validation. I have a requirement that... A value is only required if another property is specified Issue MVC binds each property and calls each validator on that property as it binds them. If I am dependent on multiple properties being set when I check validationContext.ObjectInstance.[MY

MVC 3 Unobtrusive validation of a list

青春壹個敷衍的年華 提交于 2020-01-14 09:09:11
问题 Question I have created a server-side property level validation attribute. But instead of applying it to an individual field I've applied it to a List. This allows me to validate the model as a whole. I now need to know how to convert this to work using the unobtrusive client-side validation built into MVC 3. My current code is below to illustrate my issue... Scenario The basic scenario was the ability total up all the Quantity values for every row in a List grouped by the GroupNo field. If

Dynamic validation on MVC 2

被刻印的时光 ゝ 提交于 2020-01-13 05:25:14
问题 This works fine [MetadataType(typeof(Area_Validation))] public partial class Area { ... } public class Area_Validation { [Required(ErrorMessage = "Please add this field.")] public int Email { get; set; } [Required(ErrorMessage = "Please add this field")] public string Name { get; set; } } but how about if Area_Validation is dynamically created ? for example Subscription Fields that on back-end can be created by the user and end up like this: How can I set the Metadata on each field for auto

ValidationMessage is showing on initial GET method

亡梦爱人 提交于 2019-12-25 11:34:16
问题 I am working on an MVC 4 project that is constantly showing the ValidationMessage even on a simple GET method that does no validation or model binding of complex types: //location/{locationId}/announcement [HttpGet] public ActionResult LocationMakeAnnouncement(int locationId) { var pageViewModel = this.BuildLocationMakeAnnouncementViewModel(locationId); return View(pageViewModel); } The BuildLocationMakeAnnouncementViewModel only builds up the ViewModel and doesn't touch the ModelState. Then

ValidationMessage is showing on initial GET method

喜欢而已 提交于 2019-12-25 11:34:06
问题 I am working on an MVC 4 project that is constantly showing the ValidationMessage even on a simple GET method that does no validation or model binding of complex types: //location/{locationId}/announcement [HttpGet] public ActionResult LocationMakeAnnouncement(int locationId) { var pageViewModel = this.BuildLocationMakeAnnouncementViewModel(locationId); return View(pageViewModel); } The BuildLocationMakeAnnouncementViewModel only builds up the ViewModel and doesn't touch the ModelState. Then

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

validation for dropdown in MVC3

。_饼干妹妹 提交于 2019-12-13 03:55:58
问题 I am validating a form using default MVC validation technique as follows: <div class="editor-label"> @Html.LabelFor(model => model.Company_Name) </div> <div class="editor-field"> @Html.EditorFor(model => model.Company_Name) @Html.ValidationMessageFor(model => model.Company_Name, "Company Name is required") </div> This is working fine for textboxes. When i applied the same for dropdown this is not working. <div class="editor-label"> @Html.LabelFor(model => model.State_Code, "State") </div>

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')

How to check if a <div> is valid with unobtrusive javascript

流过昼夜 提交于 2019-12-12 03:56:58
问题 I have a form which loads a div on client side. I have hard coded textbox controls with all validation attributes, similar to what it renders when loaded from server. Inside the div there is submit button, but when I click on submit all validations messages on the form are displayed. I just need only the div elements validation messages to be shown. Telerik Grid control in ajax mode, does similar thing, i.e., appends textboxes with hardcoded validation attributes on client side, but it

A List of Field Names as a String Array - LINQ Expressions

不打扰是莪最后的温柔 提交于 2019-12-11 18:08:07
问题 Hello MVC and LINQ Experts, I have a Model that looks like this: public class SomeClass : IValidatableObject { public string SomeString { get; set; } public string SomeString2 { get; set; } public int SomeInteger { get; set; } public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { //... IF there is some error...THEN yield return new ValidationResult("Some Error Message.", GetFieldNames(() => new []{ this.SomeString })); } } As you can see, I am calling