From the course: Learning ASP.NET Core MVC
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Post form data to controller actions
From the course: Learning ASP.NET Core MVC
Post form data to controller actions
- [Instructor] Now that we've got an HTML form that allows users to post data to our application, we'll need a controller action to actually accept that post data. Since ASP.NET Core MVC is posting back to the same controller name as the action that rendered the view, I'm going to start by copying and pasting the Create controller action that I just created and use that to handle the post action. Once I do this, I'll need to specify which of these actions should show the form and which one should handle the form post. This is actually pretty easy to do. I'll simply decorate each action with the corresponding attribute: HttpGet to mark which one is displaying the view and HttpPost to indicate the controller action that should handle the form post. There's another problem, though. Even with those attributes in place, the two method signatures are exactly the same, which means that this code isn't even valid C#, so our site won't even compile. That's also simple enough to fix. I'll just…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Create strongly typed HTML forms4m 5s
-
(Locked)
Post form data to controller actions4m 9s
-
(Locked)
Validate form post data5m 55s
-
(Locked)
Use tag helpers to simplify forms5m 7s
-
(Locked)
Represent the database using Entity Framework6m 9s
-
(Locked)
Write to a database using Entity Framework1m 35s
-
(Locked)
Read from a database using Entity Framework2m 26s
-
-
-
-