Header add

In this article we will learn about Display XML File data in WebGrid in ASP.Net MVC. Here we discuss how to use XML data read and fetched XML records that will be displayed in WebGrid using Model class in ASP.Net MVC.

XML File


I have the sample XML file customer.xml like below.

The XML file can be download here.

Model

Create a model of customer to hold the below properties.


Controller

The Controller consists of one Action method.

GET operation

Inside the Index Action method, the XML file is read using the XmlDocument class object.
Then the Customer Node is selected using XPath query and a loop is executed over all the selected Nodes.


View

Inside the View, in the very first line the Customer class is declared as IEnumerable which specifies that the Model will be available as a Collection.

The WebGrid is initialized with the Model i.e. IEnumerable collection of Customer class objects as source.



Output

The output like below,

How to use WebGrid in ASP.Net MVC


Post a Comment

Previous Post Next Post