Questions tagged [model-validation]

Model Validation is ASP.NET MVC validation method for your models with property attributes. Model validation works for client and server side validation.

For further information you can check Scott Gu's blog post: http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

There is a expansion called "DATA ANNOTATIONS EXTENSIONS" for other custom validation types such as CreditCard, min-max integer value etc. http://weblogs.asp.net/srkirkland/archive/2011/02/23/introducing-data-annotations-extensions.aspx

325 questions
2
votes
1 answer

Model validation with custom validation attribute

I am using model validation for my web API and I have following custom model as an example public class Address { [Required(ErrorMessage = "The firstName is mandatory")] [EnhancedStringLength(100, ErrorCode = "1234556", ErrorMessage =…
2
votes
3 answers

Email Validation in .Net mvc4

Currently I am using following code for email validation but it does validate the dsgf@g mail id please help me [Required(ErrorMessage = "Please Enter Email Id")] [Display(Name = "Email-Id")] [EmailAddress(ErrorMessage = "Invalid Email…
Ravi
  • 25
  • 1
  • 6
2
votes
2 answers

Best way to handle multiple form validation in ASP.NET MVC

Overview I have a payment page where I allow the user to select a payment method, either credit card or check. I have a form for each of these payment methods. I did not want to create a separate page for each of these methods for UI purposes, so I…
dotariel
  • 1,584
  • 12
  • 23
2
votes
1 answer

RegularExpression validation fails at ModelState.IsValid when input is 0.00

I have a problem similar to this question I'm using MVC. I have added a regular expression in my ViewModel to force the users to enter a number with 1 or 2 decimal places. I am thinking there must be an error in my Regex but the same statement is…
Ona_17
  • 35
  • 1
  • 8
2
votes
2 answers

ASP.Net MVC 2 Model Validation Regex Validator fails

I have following property in my Model Metadata class: [Required(ErrorMessage = "Spent On is required")] [RegularExpression(@"[0-1][0-9]/[0-3][0-9]/20[12][0-9]", ErrorMessage = "Please enter date in mm/dd/yyyy…
TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
2
votes
2 answers

ASP.NET WEB API 2 - ModelBinding Firing twice per request

I have a custom validation attribute, that when I make a request to the server via a POST, is firing the IsValid method on the attribute twice. Its resulting in the error message returned to be duplicated. I've checked using Fiddler that the…
Derek
  • 8,300
  • 12
  • 56
  • 88
2
votes
1 answer

Yii2 show error when exception occurs

I have this code in my controller: ... if (Model::validateMultiple($ttepk)) { $transaction = \Yii::$app->db->beginTransaction(); try { foreach ($ttepk as $ttep) { $ttep->save(false); if (!$ttep->assignPs()) { …
user2511599
  • 796
  • 1
  • 13
  • 38
2
votes
1 answer

IValidatableObject Validate method runs twice

I have a model with an Entity Framework object on it. The EF object implements IValidatableObject and has a Validate() method on it. For some reason the method runs twice, so I get two identical model errors on my page. Any idea why this happens or…
NibblyPig
  • 51,118
  • 72
  • 200
  • 356
2
votes
0 answers

Using form validation with WebAPI 2 and AngularJS

I'm a bit confused about the topic form validation / model validation with WebAPI 2 and AngularJS. In AngularJS I'm using the form validation in my view as follows:
yuro
  • 2,189
  • 6
  • 40
  • 76
2
votes
1 answer

Validating a Collection of Model in ASP.NET MVC

I have a view similarly declared on this link.
@if (Model.PersonSpecificModels != null) { for (var i = 0; i < Model.PersonSpecificModels.Count; i++) { …
Patrick
  • 318
  • 3
  • 13
2
votes
0 answers

Under posted model state always valid

I have an interesting issue. I have following model with required data annotation for some of the properties. public class Consumer : MongoEntity { public Consumer() { Products = new List(); } [Required] public…
qamar
  • 1,437
  • 1
  • 9
  • 12
2
votes
2 answers

how to make validates inclusion true or false work in testing rails?

how to make validates inclusion true or false work in testing rails? i'm using gem shoulda for my testing, if i have some validates like this in my model : class Draw < ActiveRecord::Base validates :available, inclusion: { in: [true, false]…
tardjo
  • 1,594
  • 5
  • 22
  • 38
2
votes
2 answers

ModelState validation checking multiple boolean property

I have view model that have multiple boolean properties, in my controller i have checking ModelState.IsValid before proceeding to service layer. Now I want to make that ModelState.IsValid return false if none of boolean property set to true, is…
Dion Dirza
  • 2,575
  • 2
  • 17
  • 21
2
votes
1 answer

NoMethodError: undefined method ` validate' (custom validate) RAILS 3

my item.rb # encoding: utf-8 class Item < ActiveRecord::Base attr_accessible :asin, :domain, :formatted_price, :user_id   validate :double_dates private   def double_dates     if Item.where(:user_id => self.user_id, :asin => self.asin, :domain…
whitesiroi
  • 2,725
  • 4
  • 30
  • 64
2
votes
0 answers

Regular expression data validation attribute does not return error message

I have my model: [RegularExpression("[0-9]+", ErrorMessage = "GroupId must be a number")] public int? GroupId { get; set; } And WebApi application. I expect controller to return error message like this: { "$id": "1", "Message": "GroupId must…
makambi
  • 1,100
  • 3
  • 13
  • 30