Solved

MVC Modify the Validation Message

Posted on 2014-01-08
1
142 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
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now