CRUD Function for Static Data in ASP.NET MVC

Introduction

Today we are starting the CRUD function for static data in ASP.NET MVC. In MVC it is somuch easier to generate the CRUD function.

Step 1: Begin with the same pattern; open visual studio and press the Create Project button and choose the ASP.NET Web Application, then press the OK button.

ASP.NET Web Application

Step 2: After pressing the OK button now choose a template MVC and check the MVC checkbox, and then press the OK button

template MVC

Step 3: After that left click on the Models folder which appeasr in your project and add the class and set the name Member.cs and then press the add button

Add class

Step 4: After that in class we declare some properties. The best way to write the propertiesis only type pro and then press the tab button immediately two times, now the property is made and you make any further changes.

Member page

Step 5: After that move on the HomeController.csand and add the Model which you see in the top library then make a list of Member class and put some records on it.

HomeController

Step 6: Left click on Index Method and add view, after that select the template List and also change the model class to Member class, then press the add button; now it givesan alert that you already have index file so you replace it by pressing the yes button.

add view

Step 7: Now when you run the program you can see that those records which we were put in the list now easily show here, but remember, you can see that the ID is not shown here.

run

Now we will add some additional information to show the ID attribute. Now in the upper we add the column name which is known as Member ID and in the same way we add ID attribute after the foreach loop to show the ID record.

code

Step 8: Now when you run the program you see that the Member Id attribute now appears. Remember that we perform this function for static data, not for database data

output

Ebook Download
View all
Learn
View all