Join Jess Chadwick for an in-depth discussion in this video Post form data to controller actions, part of Learning ASP.NET Core MVC.
- [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 add a parameter to differentiate the two.…
- Building blocks of ASP.NET Core applications
- Creating a new project
- Responding to HTTP requests
- Serving static files
- Understanding the MVC pattern
- Handling requests with controllers
- Rendering HTML with Razor
- Rendering data, view markup, and view logic
- Creating HTML forms
- Validating form data
- Reading and writing from a database with Entity Framework
- Improving the user experience
- Exposing data with a web API
- Securing your ASP.NET application
Skill Level Intermediate
1. The Basics
2. The Model-View-Controller (MVC) Pattern
Understand routing4m 24s
3. Render HTML with Views
4. Work with Data
5. Improve User Experience with Ajax and Web APIs
6. Secure Your Application
Next steps1m 42s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.