Posts

Showing posts with the label ASP.NET

How to Enable and Disable Client-Side Validation in MVC

MVC3 & MVC4 supports unobtrusive client-side validation. In which validation rules are defined using attributes added to the generated HTML elements. These rules are interpreted by the included JavaScript library and uses the attribute values to configure the jQuery Validation library which does the actual validation work. In this article, I would like to demonstrate various ways for enabling or disabling the client side validation. Enable Client-Side Validation in MVC For enabling client side validation, we required to include the jQuery min, validate & unobtrusive scripts in our view or layout page in the following order. <script src = "@Url.Content(" ~ / Scripts / jquery-1 .6.1. min . js ")" type = "text/javascript" ></script> <script src = "@Url.Content(" ~ / Scripts / jquery . validate . js ")" type = "text/javascript" ></script> <script src = "@Url.Content("

Difference Between Razor View Engine and ASPX View Engine

View Engine is responsible for rendering the view into html form to the browser. By default, Asp.net MVC support Web Form(ASPX) and Razor View Engine. There are many third party view engines (like Spark, Nhaml etc.) that are also available for Asp.net MVC. Now, Asp.net MVC is open source and can work with other third party view engines like Spark, Nhaml. In this article, I would like to expose the difference between Razor & Web Form View Engine. Razor View Engine VS Web Form(ASPX) View Engine Razor View Engine Web Form View Engine Razor Engine is an advanced view engine that was introduced with MVC3. This is not a new language but it is a new markup syntax. Web Form Engine is the default view engine  for the Asp.net MVC that is included with  Asp.net MVC from the beginning. The namespace for Razor Engine is  System.Web.Razor . The namespace for Webform Engine is System.Web.Mvc.WebFormViewEngine . The file extensions used with Razor Engine are different fr

Server Side Model Validation in MVC Razor

Image
Server side validations are required for ensuring that the received data is correct and valid. If the received data is valid then we do the further processing with the data. Server side validations are very important before playing with sensitive information of a user. Server-side validation must be done whether we validate the received data on the client side. User could disable script in his browser or do something else to bypass client-side validation. In this case server-side validation must required to protect our data from dirty input. Server-side model validation technique In MVC Razor, we can validate a model server side by below two ways: Explicit Model Validation Model Validation with Data Annotations Explicit Model Validation Suppose, you want to validate the registration process of a user for which the Registration model and view are defined as below: RegistrationModel.cs public class RegistrationModel { public string UserName { get ; set