Book Image

ASP.NET Core 2 Fundamentals

By : Onur Gumus, Mugilan T. S. Ragupathi
Book Image

ASP.NET Core 2 Fundamentals

By: Onur Gumus, Mugilan T. S. Ragupathi

Overview of this book

The book sets the stage with an introduction to web applications and helps you build an understanding of the tried-and-true MVC architecture. You learn all about views, from what is the Razor view engine to tagging helpers. You gain insight into what models are, how to bind them, and how to migrate database using the correct model. As you get comfortable with the world of ASP.NET, you learn about validation and routing. You also learn the advanced concepts, such as designing Rest Buy (a RESTful shopping cart application), creating entities for it, and creating EF context and migrations. By the time you are done reading the book, you will be able to optimally use ASP.NET to develop, unit test, and deploy applications like a pro.
Table of Contents (14 chapters)

Client-Side Validation


There are scenarios where we don't need to go to the server to validate the input data. In the preceding example of server-side validation, we do not need to go to the server to verify whether the user has entered the data for the Name field. We can validate at the client side itself. This prevents round-trips to the server and reduces the server load.

We are going to use JavaScript to validate the data from the client side. JavaScript is a high-level, interpreted language that is primarily used in client-side programming.

Note

At present, JavaScript is also being used at the server side as part of Node.js.

Performing Client-Side Validation

Follow these steps to perform client-side validation:

  1. We are going to make a couple of changes in our ViewModel (the Index.cshtml file) to validate the form at the client side:
    1. Changes in the form: add the id attribute to all the span tags so that we can access this HTML element to display the HTML error message. On submission of the...