What is a CDN and advantages of CDN?

CDN stands for content delivery network or content distribution network (CDN) which is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve the content (like jQuery library and other open source libraries) to end-users with high availability and… Continue reading

How to enable and disable client-side validation in ASP.NET MVC?

We can enable and disable the client-side validation by setting the values of ClientValidationEnabled & UnobtrusiveJavaScriptEnabled keys true or false. This setting will be applied to application level. <add key=”ClientValidationEnabled” value=”true” /> <add key=”UnobtrusiveJavaScriptEnabled” value=”true” /> For client-side validation, the values of above both the keys must be true. When… Continue reading

How to determine there is no error in Model State?

When server side model validation fails, errors are included in the ModelState. Hence, by using ModelState.IsValid property you can verify model state. It returns true if there is no error in ModelState else returns false. [HttpPost] public ActionResult DoSomething(UserViewModel model) { if (ModelState.IsValid) { //TODO: } return View(); }

How to apply Server side validation in ASP.NET MVC?

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… Continue reading

What is Data Annotations in ASP.NET MVC?

Data validation is a key aspect for developing web application. In Asp.net MVC, we can easily apply validation to web application by using Data Annotation attribute classes to model class. Data Annotation attribute classes are present in System.ComponentModel.DataAnnotations namespace and are available to Asp.net projects like Asp.net web application &… Continue reading

How to determine an action method is invoked by HTTP GET or POST?

By using HttpMethod property of HttpRequestBase class, you can find out whether an action is invoked by HTTP GET or POST. public ActionResult Index(int? id) { if (Request.HttpMethod == “GET”) { //TODO: } else if (Request.HttpMethod == “POST”) { //TODO: } else { //TODO: } return View(); }  

How to restrict an action method to be invoked only by HTTP GET, POST, PUT or DELETE?

By default, each and every action method can be invoked by any HTTP request (i.e. GET, PUT, POST, and DELETE). But you can restrict an action to be invoked only by a specific HTTP request by applying HttpGet or HttpPost or HttpPut or HttpDelete attribute. If you want to restrict… Continue reading

What is ActionResult and how is it different from others?

The ActionResult class is the base class for all action results. An action result can be of type ViewResult, JsonResult, RedirectResult and so on. Hence, when your action method returns multiple results based on different conditions, ActionResult is the best choice. Since it can return any type of result. public… Continue reading