Solved

MVC Modify the Validation Message

Posted on 2014-01-08
1
146 Views
Last Modified: 2014-02-18
Hi

How do I modify/customise the validation messages?

At the moment if I don't enter a field, I get "The value '' is invalid."
I would like to make this more personalised or at least change it to "You must enter this field" or "You must enter your name"
0
Comment
Question by:elmbrook
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39767844
Assuming you're using standard validation mechanism, then you can decorate the properties of your model with data annotations. Something like:
public class Person
{
     [Required(ErrorMessage = "You must enter your first name")]
     public string FirstName { get; set; }

     [Required(ErrorMessage = "You must enter your last name")]
     public string LastName { get; set; }
}

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question