CRUD Operations w/ XML Data in ASP.NET MVC 3
— ASP.NET — 2 min read
Create, read, update, and delete (CRUD) operations are easy to perform in ASP.NET MVC. By using the default T4 scaffolding templates and strongly-typed views you can quickly build a web application that can create, update, and delete records.
Using ASP.NET MVC 3 I built a simple Billing Application that performs CRUD operations on an XML file. With LINQ I was able to quickly write code to update nodes in the XML file.
How my app works
My ASP.NET MVC 3 Billing App uses the Repository pattern for accessing data. The advantages with this pattern are it makes my methods easier to maintain and limits the amount of duplicated code in the data access layer. For each CRUD operation I have a method in my repository.
I created a Billing.cs class based on the structure of my Billings.xml file.
In my Billing.cs class I used the System.ComponentModel.DataAnnotations namespace for adding validation to my model properties.
My model folder also contains my interface IBillingRepository.cs.
And all the heavy lifting is done by my BillingRepository.cs class.
I have one Controller named BillingController.cs which interacts with my repository and contains get and post requests for performing CRUD operations. By using the ModelState.AddModelError() method I am able to display Exception error messages in red font for any failed CRUD operations.
_Layout.cshtml optional RenderSection tag
ASP.NET MVC makes it easy to perform CRUD operations on data. The T4 Scaffolding templates create forms and lists for your strongly-typed Views so you don't have to waste time manually coding them yourself. These templates also provide form validation which speeds up the development process. ASP.NET MVC comes with some great tools to get your web apps up and running very quickly.