From 7f0ae08f3c0b7721ac264127e488afc4e01a7bc9 Mon Sep 17 00:00:00 2001 From: nanqi0622 Date: Sun, 25 Jan 2026 21:52:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...41\345\236\213\347\273\221\345\256\232.md" | 10 ++ ...36\346\216\245\351\205\215\347\275\256.md" | 0 ...45\346\211\276\345\212\237\350\203\275.md" | 0 .../20260123-\347\274\226\350\276\221.md" | 101 ++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 "\351\273\204\347\276\216\347\220\252/20260119-\346\250\241\345\236\213\347\273\221\345\256\232.md" create mode 100644 "\351\273\204\347\276\216\347\220\252/20260121-\350\277\236\346\216\245\351\205\215\347\275\256.md" create mode 100644 "\351\273\204\347\276\216\347\220\252/20260122-\346\237\245\346\211\276\345\212\237\350\203\275.md" create mode 100644 "\351\273\204\347\276\216\347\220\252/20260123-\347\274\226\350\276\221.md" diff --git "a/\351\273\204\347\276\216\347\220\252/20260119-\346\250\241\345\236\213\347\273\221\345\256\232.md" "b/\351\273\204\347\276\216\347\220\252/20260119-\346\250\241\345\236\213\347\273\221\345\256\232.md" new file mode 100644 index 0000000..d545b35 --- /dev/null +++ "b/\351\273\204\347\276\216\347\220\252/20260119-\346\250\241\345\236\213\347\273\221\345\256\232.md" @@ -0,0 +1,10 @@ +# 什么是模型绑定? + +模型绑定是ASP.NET Core将HTTP请求数据自动映射到控制器动作参数的过程。 + +# 绑定来源: + +路由数据(Route data) +查询字符串(Query string) +表单数据(Form data) +JSON/XML请求体 \ No newline at end of file diff --git "a/\351\273\204\347\276\216\347\220\252/20260121-\350\277\236\346\216\245\351\205\215\347\275\256.md" "b/\351\273\204\347\276\216\347\220\252/20260121-\350\277\236\346\216\245\351\205\215\347\275\256.md" new file mode 100644 index 0000000..e69de29 diff --git "a/\351\273\204\347\276\216\347\220\252/20260122-\346\237\245\346\211\276\345\212\237\350\203\275.md" "b/\351\273\204\347\276\216\347\220\252/20260122-\346\237\245\346\211\276\345\212\237\350\203\275.md" new file mode 100644 index 0000000..e69de29 diff --git "a/\351\273\204\347\276\216\347\220\252/20260123-\347\274\226\350\276\221.md" "b/\351\273\204\347\276\216\347\220\252/20260123-\347\274\226\350\276\221.md" new file mode 100644 index 0000000..a6c26c3 --- /dev/null +++ "b/\351\273\204\347\276\216\347\220\252/20260123-\347\274\226\350\276\221.md" @@ -0,0 +1,101 @@ +# +## Edit.cshtml +``` +@{ + Layout = null; +} + +@model Min.Models.Products; +
+ + + + + + + + + + + + + + + + + + + + + +
商品名称:
商品标签:
商品价格:
取消并返回列表
+
+``` +## ProductController.cs +``` + public IActionResult Edit(int id) + { + var obj=db.Products.Find(id); + if (obj == null) + { + return NotFound(); + } + return View(obj); + } + + public IActionResult EditSave(Products input) + { + var obj=db.Products.Find(input.Id); + if (obj == null) + { + return NotFound(); + } + obj.ProductName=input.ProductName; + obj.Tag=input.Tag; + obj.Price=input.Price; + db.Products.Update(obj); + db.SaveChanges(); + return Redirect("/product/index"); + } +``` +# 删除 +## Del.cshtml +``` +@{ + Layout = null; +} + +@model Min.Models.Products; +

你确认要删除如下商品吗?

+
+    @Model.Id
+    @Model.ProductName
+    @Model.Tag
+    @Model.Price
+
+确认删除 +取消删除 +``` +## ProductController.cs +``` + public IActionResult Del(int id) + { + var obj=db.Products.Find(id); + if (obj == null) + { + return NotFound(); + } + return View(obj); + } + public IActionResult DelSave(int id) + { + var obj=db.Products.Find(id); + if (obj == null) + { + return NotFound(); + } + db.Products.Remove(obj); + db.SaveChanges(); + return Redirect("/product/index"); + } +``` \ No newline at end of file -- Gitee