Join Jess Chadwick for an in-depth discussion in this video Validate form post data, part of Learning ASP.NET Core MVC.
- [Instructor] Now that we've got data posting…from the browser, back to to a controller action,…let's validate that data…so that we can make sure only clean,…legitimate data makes it into our system.…ASP.NET Core MVC has a really interesting way…of specifying validation rules…and that is by attaching them right to the properties…that they are validating.…Since our form is posting data via the post class,…let's just start decorating that class…with validation rules.…To begin with, let's mark the title…and body properties as required,…meaning that they have to have at least some text in them…in order to be valid.…
To do this, simply add the required attribute…above each of them.…This attribute lives…in the System.ComponentModel.DataAnnotations namespace…so be sure to import that.…Next, let's specify minimum and maximum lengths…for those two fields as well.…Let's say, I want the Title property…to be at least five characters long…but no longer than 100 characters.…To enforce this, I'll apply the StringLength attribute…
- 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.