Monday 29 July 2013

There are situations where some time we want to get root element of XML file or document. We can get this root element and root element name very easily. We are using "Root" property of "XDocument" class.

Here is example for this.
In this example we take on "BooksList.xml" file and we display its root element name.

C#. Net Example :
        XElement objRootElement = XDocument.Load(Server.MapPath("BooksList.xml")).Root;
        Response.Write("<b>Name of root element is : </b>" + objRootElement.Name);

VB.Net Examples :
        Dim objRootElement As XElement = XDocument.Load(Server.MapPath("BooksList.xml")).Root
        Response.Write("<b>Name of root element is : </b>" & objRootElement.Name.ToString())

Output :


Below are the books that you would like :

Tuesday 23 July 2013

Click Here to Download MVC_String_Length_ValidationUsingAnnotations.zip Example.

We can do string length validation using Annotations in MVC. We are using "StringLength" attribute for validation in this attribute we can specify how many characters we want to allow for particular field. In this, we can specify Maximum Length and Minimum Length. Minimum Length is an optional.

We can use more than one attribute on field.

Here is example for this.

Monday 15 July 2013

We can get specific attributes values from XML file or document or object using LINQ. We are using "Elements" and "Attributes" methods of XML document object to get attributes values.

Here is example for this.
In this example we take one "BooksList.xml" file. This file contains books related details and each book has ISBN number which appears as attribute in "<book>" node. We retrieve this attribute using LINQ and display on screen.

Tuesday 9 July 2013

Click Here to Download MVCValidationUsingAnnotations.zip Example.
 
Data annotations are uses for validation purposes. We can use annotations attribute on a model property. You can find data annotations in System.ComponentModel.DataAnnotations namespace. But there are attributes also available outside this namespace.

These attributes provide server-side validation and client-side validation. Here we are demonstrating "Required" attribute. This is a basic validation in each and every project or application we need required field validation.

Here is example for this.