ASP.NET MVC validation is a method for validating your models with property attributes. It works for client and server side validation.
Questions tagged [asp.net-mvc-validation]
181 questions
65
votes
4 answers
Manually invoking ModelState validation
I'm using ASP.NET MVC 3 code-first and I have added validation data annotations to my models. Here's an example model:
public class Product
{
public int ProductId { get; set; }
[Required(ErrorMessage = "Please enter a name")]
public…

Sam Huggill
- 3,106
- 3
- 29
- 34
28
votes
4 answers
MVC Razor Validation Errors showing on page load when no data has been posted
I'm messing around with data annotations. When I click on a link to go to a page, the validation messages are being displayed, but I would like to have the validation messages not show unless data has been posted.
View:
@Html.TextBoxFor(m =>…

allencoded
- 7,015
- 17
- 72
- 126
22
votes
2 answers
What does requestValidationMode="2.0" actually do?
I'm trying to solve a "A potentially dangerous Request.Form value was detected from the client" problem, and SO answers and Scott Hanselman recommend setting
in Web.config (along with adding an…

Oren A
- 5,870
- 6
- 43
- 64
19
votes
2 answers
MVC data annotations range validation not working properly
I have a RangeValidator on a property in my model to only allow Integers that are between 0 and 100. I have a partial view that displays a form to update the property via a jQuery UI dialog. I have looked at the source and can confirm that the…

stopher
- 213
- 1
- 2
- 6
18
votes
1 answer
ValidationMessageFor with model and html attribute only - MVC 3
Working on a MVC 3 application.
I need to add a class to the validation message html. I mean for span tag.
My Model
[Required(ErrorMessage = "Role Name is required")]
[RegularExpression(@"^[a-zA-Z ]+$",
ErrorMessage = "Only alphabets and…

Murali Murugesan
- 22,423
- 17
- 73
- 120
17
votes
1 answer
ASP.NET MVC TryValidateModel() Issues when Model is Modified
I have a two step form process where the first set of data is stored in session.
[IsMp4File]
[Required(ErrorMessage = "* Please select a video to upload")]
public HttpPostedFileBase VideoClip { get; set; }
[Required(ErrorMessage = "* Please select…

SimonGates
- 5,961
- 4
- 40
- 52
17
votes
2 answers
ASP.net MVC Validation Hook
I have the following view in ASP.net MVC 3:
@model Models.CreateProjectViewModel