How to automate model validation in ASP.Net Core

When we create applications that accept data from users, we must validate that data before storing it in a database. The .Net Framework not only provides validation attributes to simplify checks for required input, data types, value ranges, and patterns (e.g. email addresses and credit card numbers), but ASP.Net Core can check for validation errors in submitted HTML form values automatically. A model state in ASP.Net Core is a collection of name-value pairs, along with validation information, that is sent to the server during a POST request.

Any error messages included in the validation information are the model validation errors. The ApiController attribute introduced in ASP.Net Core 2.1 handles model state validation automatically. If the model state is invalid, it returns the appropriate error.

This article presents a discussion of how we can work with this new feature in ASP.Net Core.

Create an ASP.Net Core application in Visual Studio

In this section we will create the ASP.Net Core application we will use to learn how we can work with the ApiController attribute.

Follow the steps outlined below to create a new ASP.Net Core project in Visual Studio 2017.

Laser TagEnjoy a game of Laser Tag in the comfort of your own home. This pair of mini combat laser tag pistols are great fun and will keep you busy for hours as you run, hide, aim and shoot at your opponent. Tag your targets and score points, you have 3 lives each and it the first contender to lose all their lives loses. When a gun registers a hit from the other pistol, this means you lose a life. Makes a great gift or an ideal game for a party. These Laser Tag guns can easily attach to your keychain meaning you can carry it whilst on the move. These guns require 3xAG13 batteries (included) in each to operate.     - More Info

Laser TagLaser Tag 2. All LEDs are scarlet red 3. All LEDs flash upon impact Requires 6 x AA batteries (Not included) - More Info

Our crew neck, short sleeved men's t shirts are 100% premium cotton in a soft pre-shrunk jersey knit. Our women's t shirts are lighter weight 150g tees made with deluxe 30's soft style yarns for a soft feel." alt="Tag T Shirt" title="Tag T Shirt" width="150" height="150">Hashtag, you’re it. Combining childhood games with technology. T Shirt design reads: < you're it >Our crew neck, short sleeved men's t shirts are 100% premium cotton in a soft pre-shrunk jersey knit. Our women's t shirts are lighter weight 150g tees made with deluxe 30's soft style yarns for a soft feel. - More Info

Engraved Pet TagSince 1992 it's been mandatory for any dog in a public place to wear a collar with the owner's details on it.You could settle for a plain, boring collar and hand write your details on it or you could show everyone who's really top dog with our engraved pet tag!On one side of the circular tag is a silver paw print design overlaid on a sleek, black glittery background. Flip the tag over and there's room for four lines of your details. Our expert engravers will ensure your personal info is clear, readable and resistant to all-weathers.Make your dog the envy of owners and dogs alike with our Engraved Pet Tag. Also suitable for feline friends!Dimensions: 35mm(L) x 25mm(W) x 1mm(D). - More Info

Retirement Gift TagMake a leaving gift extra special by adding a bespoke label to your co workers retirement gift. A personalised gift tag doubles up as a modern gift card and can be kept in the home after the present has been opened (or the wine has been drank). The recipient could hang it up on a window latch or cupboard door handle and it will remind them of all the happy memories from their workplace. Dimensions: Measures approx 3.5cm wide x 6cm high and 3mm deep. Material: Made from clear acrylic. - More Info

You may also like...

       
Apps & Games Clothing Electronics & Photo Large Appliances
Baby Womens Apparel Garden Lighting
Beauty Mens Apparel Outdoors Luggage
Books Girls Apparel Health & Personal Care Pet Supplies
Car Boys Apparel Home Shoes & Bags
Motorbike Computers & Accessories Kitchen Equipment Sports & Outdoors
Fashion DIY & Tools Jewellery Toys & Games