1. Browsing Classification
A. Modify contoller as follows:
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. Web; Using System. Web. MVC; Using Bookshop. models; // Import Model Namespace Bookshop. controllers { Public Class Categorycontroller: controller {bookshopdbdatacontext DB = New Bookshopdbdatacontext (); // Category/List Public Void List () {list <Category> categories = dB. getallcategory (); renderview ( "Categorylist" , Categories );} // Category/edit/ID Public Void Edit ( Int ID ){} // Category/delete/ID Public Void Delete ( Int ID ){} // Category/Add Public Void Add (){}}}
B. Create a corresponding category folder under the View File and create a (MVC View content page) categorylist. aspx
C. Modify categorylist. aspx. CS as follows:Code:
D. Modify the category. aspx view.
E. Browse (because there is no data in the database, as shown in)
2. Add a directory
A. Now we can implement the new function, modify the Add action of categorycontroller, create an addsaved action, save the newly created directory, and navigate to the List View.
// Category/Add
Public Void Add ()
{
Renderview ( " Addcategory " );
}
Public Void Addsaved ()
{
CATEGORY newcategory = New CATEGORY {categoryname = Request. Form [ " Categoryname " ]};
DB. addcategory (newcategory );
Redirecttoaction ( New Routevaluedictionary ( New {Controller = " Category " , Action = " List " }));
}
B. Create an addcategory. aspx (MVC View content page) under view \ category \ to create a new view.
C. Final Results
3. Modify the directory:
A. Add the following two methods to the bookshopdbdatacontext partial class:
// Edit category
Public Void Editcategory (category C)
{
This . Updatecategory (C );
This . Submitchanges ();
}
PublicCATEGORY getcategory (IntID)
{
ReturnCategories. Single (C=>C. categoryid=ID );
}
B. Add the following method to categorycontroller.
// Category/edit/ID
Public Void Edit ( Int ID)
{
Renderview ( " Editcategory " , DB. getcategory (ID ));
}
Public Void Editsaved ( Int ID)
{
Category C = DB. getcategory (ID );
C. categoryname = Request. Form [ " Categoryname " ];
// Bindinghelperextensions. updatefrom (C, request. form );
DB. editcategory (C );
List < Category > Categories = DB. getallcategory ();
Redirecttoaction ( New Routevaluedictionary ( New {Controller = " Category " , Action = " List " }));
}
C. Create an editcategory. aspx (MVC View content page) under view \ category \ to create a new view.
Modify categorylist. aspx
Modify editcategory. aspx. CS as follows:
Modify editcategory. aspx as follows:
D. effect:
4. delete a directory
A. Modify categorylist. aspx
B. Modify categorycontroller and add
C. Effect
Not complete...