Asp .Net MVC DataAnnotation Range Attribute

Facebook Twitter Google Digg Reddit LinkedIn Pinterest StumbleUpon Email

So far, we have looked at a few DataAnnotation attributes namely, Required, Compare and Display. Following are the links to these blogs posts.

In this short blog post we will look at another important DataAnnotaion attribute, [Range].

Along with all the other Asset details, let's say we want to capture the Year in which the asset was purchased. We can simply add a new property in our model and Modify the View to have a new input field. However we have a requirement that value for this field must be between certain range.

This is the very good example to utilize yet another DataAnnotation attribute named Range. As the name suggest this attribute helps us validate user input between certain range. The first parameter of this attribute is the Minimum possible value and the second parameter is the Maxmimum possible value for the field.

Let's go ahead and make changes to our Model class so that it looks something like below.


Asp .Net MVC DataAnnotation Display Attribute

Facebook Twitter Google Digg Reddit LinkedIn Pinterest StumbleUpon Email

So far, we have looked at the two DataAnnotation attributes, [Required] and [Compare]. Following are the links to these topics in case you have missed them.

In this short blog post we will look at another important DataAnnotaion attribute, [Display].

So far, when we created our forms using the @Html.LabelFor HtmlHelper our Create Asset screen looked something like this.


Asp .Net MVC DataAnnotation Compare Attribute

Facebook Twitter Google Digg Reddit LinkedIn Pinterest StumbleUpon Email

In following previous blog posts related to Asp .Net MVC DataAnnotaion, we have looked at how to start building and Asp .Net MVC application from scratch and how DataAnnotaion works.

To continue on our series of Asp .Net MVC validation topic, let's explore another very important [Compare] DataAnnotaion attribute.

Form our previous post, let's go ahead and create couple of new properties on our Asset model class.


Asp .Net MVC DataAnnotation Required Attribute

Facebook Twitter Google Digg Reddit LinkedIn Pinterest StumbleUpon Email

Validation is a key part of any web application we build. Building web applications with Asp .Net MVC Framework has a lot of benefits and one of them is validation using DataAnnotation.

In this blog post we will go through the basics of DataAnnotaiton and see how this can make our life easier while working with data validations. DataAnnotaiton works with other two components to provide us a robust client side validation. These components are

Following are some of the attributes available out of the box in System.ComponentModel.DataAnnotations Namespace.

  • Required
  • Compare
  • Display
  • Range

The [Required] DataAnnotation Attribute

This is the most commonly used and easiest to understand attribute of all. As the name suggests, when you want to make an input field required just decorate that Property in your C# class with [Required] attribute and everything else will be done auto-magically.

To continue reading further you will need the a basic MVC 4 application. If you are new to MVC 4 and not sure from where to start please refer to this blog post. It describes a step by step process to create an empty Asp .Net MVC application.

Once you follow along that post you should have a pretty clean Asp .Net MVC application built from scratch. Now, let's go ahead and add a new Controller AssetController. To examine the DataAnnotation we will be creating an imaginary Asset Management Application and the screen to enter Asset details.


Execute C# Function in Windows 8 App From WebView Page

Facebook Twitter Google Digg Reddit LinkedIn Pinterest StumbleUpon Email

In last couple of blog posts we have been looking at the different use cases of WebView Control. In order to follow along with this post you should have basic understanding of WebView Control. If not, go through below posts to get the basic idea about this control.

  1. Working with the XAML WebView Control
  2. Invoking JavaScript Form Windows8 App Inside WebView Page

In this blog post we will take a look at following two scenarios.

  • How we can construct the dynamic HTML content and navigate our WebView control to that dynamically generated content.
  • how we can invoke a C# function inside our Windows 8 Application from JavaScript function.

For the first one we will be using the NavigateToString function from WebView control. And for invoking our C# function from JavaScript we will be using ScriptNotify function.

I am using the Project we built in previous blog post. You might want to quickly read through that to follow along with this post.

Constructing the Dynamic HTML in Windows 8 Application

We have added a new button, on the click event of that button we will navigate to the dynamic HTML we have constructed.