Asp .Net MVC Remote Validation

Facebook Twitter Google Digg Reddit LinkedIn Pinterest StumbleUpon Email

In previous blog posts, we have seen different DataAnnotations attributes provided as part of .Net Framework. In this blog post we will explore once such attribute Remote. Following links refers to other DataAnnotation attributes.

Generally, there are two types of validations we enforce in our applications. One is the client side validation and the other is the server side validation.

Implementing the client side validation mainly involves writing custom JavaScript that performs validation just on the browser itself. The server side validations are obviously performed on the server side, with server side scripting language. The challenge is what if I want to carry out a validation on the client but with the help of some data on the server side.

In Asp .Net, we have used technique like AJAX to perform such validations. But with Asp .Net MVC things are much more simpler, thanks to jQuery and .Net DataAnnotations.

In this blog we will go over the technique called RemoteValidation in Asp .Net MVC Framework.

The [Remote] DataAnnotation Attribute

One of the attribute of Asp .Net DataAnnotation is [Remote]. Based on the parameters provided to this attribute, it will automatically generate the Ajax request on our behalf to perform the validation on the server side. So idea is still the same but we will not have to do lot of JavaScripting.

Creating Asp .Net MVC 4 Application

Let's start by creating the new Asp .Net MVC 4 application.


Installing Windows 8.1 in Hyper-V

Facebook Twitter Google Digg Reddit LinkedIn Pinterest StumbleUpon Email

In this short blog post we will see how to install Windows 8.1 preview (Windows Blue) using Windows 8 Professional and Hyper-V.

To follow along with this blog post you need following things

First of all we need to enable Hyper-V feature in our system if it is not currently enabled. Running Windows 8 Professional you should have this service already running. In case it is not following are the steps to enable the Hyper-V Services.

Open Control Panel and select Programs


Applying CSS Class To Html.TextBoxFor

Facebook Twitter Google Digg Reddit LinkedIn Pinterest StumbleUpon Email

Working with the Asp .Net MVC application we use a lot of HtmlHelper(s). While using this helpers, we might want to apply some styling attribute to our components. In this short blog post we will see how we can apply CSS class while using Html.TextBoxFor HtmlHelper.

To look at the example, we will continue with our WhiteLabel solution we built in one of our previous blog post. Again, we have a model class let's say Asset and we want to apply a CSS class when we use Html.TextBoxFor HtmlHelper.


Make Html.TextBoxFor ReadOnly In Asp .Net MVC

Facebook Twitter Google Digg Reddit LinkedIn Pinterest StumbleUpon Email

While working with Asp .Net MVC applications, you come across a need to make a specific field ReadOnly. Prior to Asp .Net MVC when we worked with Asp .Net, making a TextBox readonly was as simple as marking the ReadOnly property to True.

With MVC things are bit different. We use HtmlHelper provided by Asp .Net MVC Framework to generate fields for our form. The HtmlHelper we use to create the input field is @Html.TextBoxFor.

Let's see how we can mark our input field as ReadOnly using this Helper. To demonstrate this I will be using the WhiteLabel solution I have built in one of my previous blog post.

With that solution with me, let's say I have a Model class Asset and following is the Form that takes user input for this Model class. Notice the Html.TextBoxFor HtmlHelper in the screen shot.