Back to Course
Լight modeDark mode

CRUD Step-by-Step >Add Standard and Custom Validations

Episode Description

What is a form without necessary Validations? 

When you are building a web application, it is important to have validations in place to ensure that the data being submitted is accurate. This is especially important when you are dealing with sensitive information such as credit card numbers or password. By using validations, you can help to protect your users' data and keep your application secure.

Focus on important code:

//custom validation List listProduct = _Dbcontext.Product.FromSqlRaw("Select * from Product Where ProductName ='" + product.ProductName.Trim() + "'").ToList(); if (listProduct.Count > 0){PopulateCategories(); ModelState.AddModelError("ProductName", "Product Name already exists in table"); return View(product); }//end of vaidation