Please see my other MVC articles.
Enabling specific actions for GET and POST calls.
MVC provided an elegant method to specify actions based on the type of call used by the webpage – GET (default) Http verb or POST Http verb.
To illustrate this ability, I’ll begin where my Form Validation article left off with a Controller, Model, and View (displaying a user-input form) already created.
As you’ll see in my Model, I’ve updated my first action method with the “[HttpGet]” attribute to denote it will respond with the webpage uses the GET call.
Also, I’ve added a new action method that will specifically respond when a page posts data back.
Now I will create another strongly-typed View to display a confirmation message so the user knows that we’ve received their input.
Notice in my [HttPost] action method that I’m passing the name of the View – “Thanks.” Since the View is strongly-typed, I have immediate access to the Model’s fname and lname properties.
Upon submitting the form with my information, I now receive a confirmation message including the name I entered within the “Thanks” View.