本文共 1401 字,大约阅读时间需要 4 分钟。
1、浏览分类
a. 修改Contoller的为如下
// 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. 我们需要在view\category\下建一个AddCategory.aspx(MVC view content page)来新建一个视图
c. 最终效果
3. 修改目录:
a. 添加下面两个方法到BookShopDBDataContext分部类
// Edit Category public void EditCategory(Category c) { this .UpdateCategory(c); this .SubmitChanges(); } public Category GetCategory( int id) { return Categories.Single(c => c.CategoryId == id); } b. 添加下面的方法到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. 我们需要在view\category\下建一个EditCategory.aspx(MVC view content page)来新建一个视图
修改CategoryList.aspx
修改EditCategory.aspx.cs如下
修改EditCategory.aspx如下
d.效果:
未完待续。。。
本文转自敏捷的水博客园博客,原文链接http://www.cnblogs.com/cnblogsfans/archive/2008/03/26/1123037.html如需转载请自行联系原作者
王德水