ASP.NET MVC+LINQ开发一个图书销售站点(7):图书分类管理

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)来新建一个视图

image

c. 最终效果

image

image

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

image image

修改EditCategory.aspx.cs如下

image

修改EditCategory.aspx如下

image

d.效果:

 

<style type="text/css">.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值