Asp .Net MVC DataAnnotation Compare Attribute

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

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

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.

Invoking JavaScript From Windows8 App Inside WebView Page

In the previous blog post, we looked at basics of the WebView component. Once you are comfortable with the basic operations, you would want to perform some advanced operations. In this bog post we will examine two such advanced scenarios.

The key function we will be using to invoke the script on our HTML page is InvokeScript function provided by WebView Component.

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

Adding HTML page into our Windows 8 Store Application Project

First off, let's start by creating a new HTML page in your application. I have added this HTML page in the Asset Folder.

Working with the XAML WebView Control

Once you start working with the Windows 8 Store application, soon you will find yourself with the requirement to show HTML pages into your native Windows 8 Store App. And sure thing, that first thing that comes to your mind is, is there any component out there which does this!! And in fact, there is.

Microsoft's Windows 8 team has provided as with the component called WebView.In this blog post we will start examining the basic features of this WebView component and in new few blog posts we will see some of the advanced scenario with this Control.

Creating The Windows 8 Application

So, to start with let's create a new Windows 8 Store Application. Certainly we will be using XAML and C# as our platform because that is where we have the issue o displaying the HTML pages.