10-4 Episode 37: Leveraging Model Metadata and Validation with ASP.NET MVC2
- Posted: Jan 07, 2010 at 9:21 AM
- 17,010 Views
- 7 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
In this episode of 10-4, we discuss a new feature coming in the next release of ASP.NET MVC: model metadata and validation. This allows you to associate validation rules and metadata with your model and have the runtime perform validation automatically. In addition, you can also have JavaScript emitted that will provide client-side validation as well, making it dead simple to achieve a rich client and server validation experience with any web application.
For more 10-4 episodes, be sure to visit: http://channel9.msdn.com/shows/10-4
Visual Studio Topic Area on Channel 9: http://channel9.msdn.com/VisualStudio
10-4! Over and out!
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
I like it, but is there a way to create a user friendly message for the REGEXP validation?
Ditto on the RegEx validation question. Great presentation and awesome technology!
Great question, and fortunately the answer is yes
I tried to keep the video short, so I couldn't go into every scenario, but all of the validation messages can be customized, as well as localized by using resource files. In the video I just simply used
the default messages for example.
In your demo you had a reference to jquery.validation? How easy to use it on the client-side?
The client-side validation that MVC uses is fully extensible, and it's pretty simple to wire-up a custom implementation. Out of the box, the validation uses MS AJAX, and if you want to use jQuery validation, there is an implementation of that in the MVC futures project (here). If you have any troubles getting it to work, feel free to e-mail me (joncart at microsoft dot com).
This handles formatting validation well. Could I add a custom validation? For example, can I verify that a new airport code is unique in the database? Does that belong somewhere else?
Hi,



I’ve just started a new project in ASP.net 4.0 with MVC 2.
What I need to be able to do is have a custom hook at the start and end of each action of the controller.
e.g.
public void Index() {
*** call to the start custom hook to externalfile.cs (is empty so does nothing)
ViewData["welcomeMessage"] = "Hello World";
*** call to the end custom hook to externalfile.cs (changes "Hello World!" to "Hi World")
return View();
}
The View then see welcomeMessage as “Hi World” after being changed in the custom hook.
The custom hook would need to be in an external file and not change the “core” compiled code. This causes a problem as with my limited knowledge ASP.net MVC has to be compiled.
Does anyone have any advice on how this can be achieved?
Thanks
Remove this comment
Remove this thread
close