10-4 Episode 37: Leveraging Model Metadata and Validation with ASP.NET MVC2
- Posted: Jan 07, 2010 at 9:21 AM
- 15,903 Views
- 7 Comments
Download
How do I download the videos?
- To download, right click the file type you would like and pick “Save target as…” or “Save link as…”
Why should I download videos from Channel9?
- It's an easy way to save the videos you like locally.
- You can save the videos in order to watch them offline.
- If all you want is to hear the audio, you can download the MP3!
Which version should I choose?
- If you want to view the video on your PC, Xbox or Media Center, download the High Quality WMV file (this is the highest quality version we have available).
- If you'd like a lower bitrate version, to reduce the download time or cost, then choose the Medium Quality WMV file.
- If you have a Zune, WP7, iPhone, iPad, or iPod device, choose the low or medium MP4 file.
- If you just want to hear the audio of the video, choose the MP3 file.
Right click “Save as…”
- MP3 (Audio only)
- MP4 (iPod, Zune HD)
- Mid Quality WMV (Lo-band, Mobile)
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 Closed
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
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