• How to add Client Side validation using Model in ASP.NET MVC 4?

    by  • October 3, 2015 • Microsoft .NET Framework, Microsoft ASP.NET MVC • 0 Comments

    Introduction:                                     

    Client side validation is necessary to add in web based project. Many developers used JavaScript in most of time to implement validation. This article explains how to add validation using Model in ASP.NET MVC 4. Implement validation through Model in ASP.NET MVC is very robust way.

    Model Class:

    In ASP.NET MVC validate a model using Data Annotations. Data Annotations allow us to govern a set of rules in model that are used to validation.

    For using DataAnnotations, we need to add  “System.ComponentModel.DataAnnotations;” in model class.

    Controller.cs:

     

    View:

    In view, add line @Html.ValidationSummary(true) inside BeginForm() method and add  @Html.ValidationMessageFor(model => model.Name) below to every textbox.

     

     

     




    Namecheap.com
    Avatar of Abdul Rehman

    About

    Abdul Rehman writes on .NET technologies at GetCodeSnippet.com. GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.

    http://getcodesnippet.com

    Leave a Reply