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 0000000000000000000000000000000000000000..d545b351617fab8c617336f6effd3aade84ec34b --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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 0000000000000000000000000000000000000000..a6c26c38d53bfa7446d3155f7af28e2f1b731f21 --- /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