Ian Boyd
Ian Boyd

Reputation: 256911

How to show validation messages in MVC?

When a user tries to click:

       Save

and they have entered in some invalid data, i want to notify them. This can be with methods such as:

What is the mechanism where a controller tells the view to show a validation message for some controls, given that different views have different notification methods?

p.s. the controller doesn't know the order that controls are physically arranged in the view (e.g. LTR locale wants to notify the user in a top-down-left-to-right visual order, while RTL locale wants to notify the user in a bottom-up-right-to-left order)

Upvotes: 2

Views: 450

Answers (2)

Mahesh Velaga
Mahesh Velaga

Reputation: 21971

If you are using ASP.Net MVC 2.0, check out this post by Scott Gu, although some of this will apply for ASP.Net MVC 1.0 as well.

Upvotes: 1

matt b
matt b

Reputation: 139971

The controller can add a Validation object to the Model, which can contain the names of the fields which were invalid, specific validation messages, etc.

The View can then choose to render this Validation object however it wishes: by highlighting the incorrect fields, animating something, showing a modal dialog, etc.

Upvotes: 1

Related Questions