Create an ASP.NET MVC Data-based Web App Pt 6 - Create, Edit, Update, Delete Fabrics

Now for the fun part, we need the ability to Create New fabrics, Edit Fabric details, Update Fabrics (the same as Edit), and Delete Fabrics from the database. We probably don't want that on the home page, first let's go to the _Layout.cshtml view of the application...

Step 1: Under the Views folder, Shared, open the _Layout.cshtml file.

Step 2: Create an ActionLink under the Contact link in the main navbar. Just copy and paste the Contact ActionLink to make it easier.
We are going to create a FabricController so, change the code to following:

<li>@Html.ActionLink("Fabrics", "Index", "Fabric")</li>

This creates a link in the navbar called Fabrics that points to the Index action on the Fabric Controller. Now we need to create the FabricController...

Step 3: Right-click on the Controllers folder, Add > New Item...


Select the template "MVC 5 Controller with views, using Entity Framework", Click Add.

Model Class: Fabric
Data Context Class: MyFabricStashDb
Controller Name: FabricController

Then, click Add. Visual Studio will scaffold the proper actions and views for you.

Step 4: Build the application and Run it (Ctrl + F5). You should see the link at the top for "Fabrics". Click on it, you will see a table with a list of Fabrics in the database.

I edited the HTML of the view for the list of fabrics the same as the home page. The image thumbnail is on the left and the fabric information summary is on the right with a horizontal bar in between individual listings.

Now, let's create our control for uploading and saving an image for each fabric in the database. On to part 7 -> Uploading and saving image files to the database...







Add comment