MVC Demo 增刪查改

2021-08-26 19:02:23 字數 1443 閱讀 8738

本例項使用linq to sql.

db所需要的表:1.product,2.category 如下圖

1.先建立列表頁面

先建立index 的control,在control資料夾下建立productcontrol 檔案(在這之前你要使用linq to sql 建立testdb檔案與db通訊,我這裡使用的資料庫是test,並將product,category 新增到testdb.dbml檔案中)

public class productcontroller : controller return view(products.tolist()); } }在model 資料夾中建立productmodelview檔案

public class productmodelview }在view資料夾中建立product資料夾,然後在建立index.cshtml

@model list@@html.actionlink("new create", "create") @using (html.beginform("index","product","index")) id

productname

createtime

price

@foreach (var item in model) ) @html.actionlink("delete", "delete", new )

} 此時列表頁面已經完成

2.建立新增頁面

進入productcontrol檔案,新增如下**

public actionresult create() [httppost] public actionresult addproduct(product product) public listgetcategoryitems() ; listitems = new list(); items.add(new selectlistitem() ); items.addrange(categorys); return items; }然後滑鼠放在create上面建立view

@model musicstore.product @@using (html.beginform("addproduct","product"))

3.建立編輯介面

進入productcontrol檔案,新增如下**

然後新增edit 的view

@model musicstore.models.productmodelview @@using (html.beginform("update", "product"))

4.新增刪除功能

進入productcontrol新增如下**即可

public actionresult delete(int id)

MongoDB增刪查改

mongodb沒有建立資料庫的命令,但是你可以先執行use db name來進行一些操作,如db.createcollection db table 這樣就可以建立乙個db name的資料庫了。以下語句其實都不用加引號 insert方法 insert obj db.test.insert write...

sed 增刪查改

對每行處理,文字替換 1.替換 s命令 sed s jcdd ganji g file 把檔案 file 中出現jcdd 的換出ganji.g標誌在整行範圍內把jcdd都替換為ganji。如果沒有g 標記,則只有每行第乙個匹配的jcdd被替換成ganji。g換出 ng代表 第n處開始出現的替換 se...

angular增刪查改

數量排序 ng model numsby 數量正序 數量倒序 ng click deleteall 批量刪除 ng click selectall 產品編號 產品名稱 購買數量 產品單價 產品總價 操作ng repeat x in product filter orderby numsby clas...