10-4 Episode 37: Leveraging Model Metadata and Validation with ASP.NET MVC2

Sign in to queue

Description

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: https://channel9.msdn.com/shows/10-4

Visual Studio Topic Area on Channel 9: https://channel9.msdn.com/VisualStudio


10-4! Over and out!

Embed

Download

Download this episode

The Discussion

  • User profile image
    LDARBY

    I like it, but is there a way to create a user friendly message for the REGEXP validation?

  • User profile image
    DatSure

    Ditto on the RegEx validation question.  Great presentation and awesome technology!

  • User profile image
    LostIn​Tangent

    Great question, and fortunately the answer is yes Smiley 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.

  • User profile image
    miksh7

    In your demo you had a reference to jquery.validation? How easy to use it on the client-side?

  • User profile image
    LostIn​Tangent

    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).

  • User profile image
    Zack Peterson

    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?

  • User profile image
    stavez

    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?

    ThanksGeneric Comment Imagecomputerslanditcomputer computerslookup laptop video card sevenwebhosting.org

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.