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

ASP.NET MVC How can I find which attribute has been error

I want there was an error in ModelBinder,automatically append an error code in the ModelState. so I had extends the default attribute to add a property.(about RequiredAttribute,RangeAttribute etc.) like: //new Attribute public class…
zt9788
  • 948
  • 4
  • 16
  • 31
2
votes
0 answers

Mvc4 Date validation format not working dd/MM/yyyy with Bootstrap datepicker

Hell, I want to add manually date in Text box with date format dd/MM/yyyy.. I have declared model validation, but i have found that MVc will not take part for Date validation, need to do with jquery, I have done like that but. here my some cases not…
2
votes
1 answer

User customizable validation with metadata saved in a database

I'm working on an application which should validate the model based on some metadata saved in a database. The purpose of this is to allow administrators change how some models are validated, without changing the code, depending on clients'…
Mihail Alexe
  • 340
  • 2
  • 9
2
votes
1 answer

MVC3 Remote Validation with DataAnnotationsModelValidator adapter

I want to validate various telephone number properties on a DTO property of my model using a custom DataAnnotationsAttribute. I don't want to duplicate the DataAnnotations onto ViewModels, to keep the code DRY, and instead I have registered a…
2
votes
2 answers

Throwing exceptions in getters and setters

I was wondering what the best practice is for model validation when it comes to using getters and setters. Specifically, I have nullable fields in my model that, in some use cases, should not have null values when accessed. In those cases, I would…
Matt
  • 23,363
  • 39
  • 111
  • 152
2
votes
0 answers

MVC4: ModelState.IsValid always returns true

I have a PartialView that contains a form that asynchronously posts data to my controller. The controller will add the user if the ModelState is valid, if not, it will return the PartialView with the invalid model. The problem I'm running into is…
bflemi3
  • 6,698
  • 20
  • 88
  • 155
2
votes
1 answer

Custom Validation for Duplicate doesn't work

I want to create custom validation for duplicate User name and E-mail. Model is so: public class RegisterModel { [Required( ErrorMessage = "Username is empty" )] [StringLength( 100, ErrorMessage = "Minimum 5 symbol", MinimumLength = 5 )] …
1
vote
2 answers

Forcing Id and UserName to be unique in ASP.NET MVC 3 Model

In my ASP.NET web site users model, I want both Guid Id's and String UserNames to be unique. I am going to map my model objects to a DB using Entity Framework. Is there a build-in attribute or some other mechanism that facilitates this common…
Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
1
vote
4 answers

rails model validation in the database

I have a table and have the validation for uniqueness setup in the table. eg. create table posts ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY UNIQUE, title varchar(255) unique, content text ); Here title is unique. Do also need to inform the model…
kiran
  • 477
  • 1
  • 7
  • 11
1
vote
1 answer

How to do Prisma runtime model validation?

In my application, I have validated the input credential at the DTO level by using class-validator. But I need runtime model validation like sequelize ORM. In sequelize: 'use strict'; import { DataTypes, Sequelize } from 'sequelize'; function…
david Billian
  • 93
  • 1
  • 8
1
vote
1 answer

IValidatableObject not triggered

I'm trying to make use of the IValidatableObject as described here http://davidhayden.com/blog/dave/archive/2010/12/31/ASPNETMVC3ValidationIValidatableObject.aspx. But it just wont fire when I'm trying to validate, the ModelState.IsValid is always…
1
vote
1 answer

Runtime Model Validation when Posting in .net core frontend

My current requirements are overriding validation at runtime when validating a models state after posting a form. I have a working solution of using normal Data Annotations for model state validation, that's standard in the world of .net, but what I…
1
vote
0 answers

ModelValidationException: Validation of the application resource model has failed during application initialization

When I have @Auth and a body(object) in a POST API in Dropwizard getting the following error while running Tests: Caused by: org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during…
Raj
  • 11
  • 1
1
vote
1 answer

Rails 7 - ActiveModel date validation | Is there a replacement for validates_timeliness gem?

While trying to upgrade my application to Rails 7, I came across the following deprecation warning : ActiveRecord::Base.default_timezone is deprecated and will be removed in Rails 7.1. Use ActiveRecord.default_timezone instead. On further…
1
vote
0 answers

How to validate models without Model validation in asp.net core MVC

Model: public class TransactionViewModel { [Key] public int Transaction_Id { get; set; } public string Account_Name { get; set; } public string Type { get; set; } public string Note { get; set; } public DateTime Date { get;…
arunachal
  • 11
  • 2