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
0
votes
1 answer

How to customise HTML markup generated by ValidationMessageFor in MVC

I am working on a MVC 4 project which requires to generate a specific markup when there is any error raise by the model validation. suppose :
Error Message
I have tried jquery to update the markup…
Mayank
  • 1,351
  • 5
  • 23
  • 42
0
votes
3 answers

ASP.NET MVC 2.0 Custom Client Validation

I am trying to make a validator that will make sure that at least 2 items are selected. The validator works correctly on the server side but the client side code never gets executed. Here is the code: …
azamsharp
  • 19,710
  • 36
  • 144
  • 222
0
votes
1 answer

error:Field required in .net c# when not indicated in the model

I am new with .net c# and I have an error while I check if the model is valid, looking at ehe errors in the model it says: "The EndRepeat field is required." Here are some of the lines of my model: [Required(ErrorMessage = "Frecuencia…
aricca
  • 1
  • 1
0
votes
1 answer

Uniqueness validation on datetime field with scope

This is my model file. class Attendance < ActiveRecord::Base belongs_to :staff, class_name: 'User', foreign_key: 'staff_id', inverse_of: :attendances belongs_to :child, inverse_of: :attendances validates :attendance_date, uniqueness: {scope:…
0
votes
2 answers

Marking a Field as Required

If I have a dbml file that contains say a Customer class with say a single property of CompanyName; public partial class Customer : INotifyPropertyChanging, INotifyPropertyChanged private string _CompanyName; public string CompanyName { get Now,…
griegs
  • 22,624
  • 33
  • 128
  • 205
0
votes
0 answers

MVC Decimal? Incremental Validation

Is it possible, in addition to adding a range to an decimal? apply increments such as only divisible by 100 to be true? [Required(ErrorMessage = "Amount is Required")] [Range(1000, 25000, ErrorMessage = "Loan must be between 1000 and…
iggyweb
  • 2,373
  • 12
  • 47
  • 77
0
votes
1 answer

Detect whether or not a specific attribute was valid on the model

Having created my own validation attribute deriving from System.ComponentModel.DataAnnotations.ValidationAttribute, I wish to be able to detect from my controller, whether or not that specific attribute was valid on the model. My setup: public class…
Sir Code-A-Lot
  • 595
  • 6
  • 16
0
votes
2 answers

Rails authentication from scratch, skip current password validation

I have an auth system from scratch, and when a user clicks on 'edit profile' it has to input the current password no matter the field he wants to edit. def update if params[:user][:password].present? authenticated =…
0
votes
1 answer

ValidateModel Problem with DataAnnotations

I have a SearchViewModel with these properties: [RegularExpression("name")] public String SortField; [RegularExpression("asc|desc")] public String SortDirection; As you can see, I want "name" to be the only valid value of SortField…
Alex
  • 75,813
  • 86
  • 255
  • 348
0
votes
0 answers

ASP.NET WEB API 2: Role or Claim dependent model validation

I have a unique requirement that I'm not sure how to handle. We are working with an underlying repository that allows for a quite a bit of flexibility with regards to parameters. The Controller services are injected as "service" objects into a…
Hardrada
  • 728
  • 8
  • 19
0
votes
1 answer

EmailAddress Validation ModelValidation firing automatically even before the user finished entering data

I am using data annotation to validate mvc4 model. Field [Required(ErrorMessage="Please fill your Email Address")] [EmailAddress(ErrorMessage="Please enter your active email so we can reply to your email.")] public string UserEmail…
0
votes
1 answer

unable to add attribute value on Error message

i have a custom validation method on user_calendar model: class UserCalendar < ActiveRecord::Base belongs_to :user validate :should_match_company_calendars ... private def should_match_company_calendars day_company_calendars =…
ntonnelier
  • 1,539
  • 3
  • 23
  • 49
0
votes
0 answers

How to add custom message from Key Value pair to the model validation error messages

Hi I just got question where i need to assign the error messages for my model validation from key value pair, i tried with the ModelState.AddModelError("TaskName","Error Message"), but i need some thing more reliable and Error messages are residing…
0
votes
0 answers

MVC Model Validation Event

Is there some kind of OnModelValidating event in MVC? Or is there another way to run some code during the model validation process?
just.another.programmer
  • 8,579
  • 8
  • 51
  • 90
0
votes
1 answer

asp.net submitdate showing up as required field when its not

I have the following model in my ASP.NET application. I had a required validator on SubmitDate but have since removed it. However when I try to submit an entry into my DB via the web field, I still get a "SubmitDate is a required field". namespace…