From f5ebfefc005d6d4406c84ecf247b8580eb369034 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 24 Nov 2024 21:49:08 +0800 Subject: [PATCH] =?UTF-8?q?'=E6=8E=A7=E5=88=B6=E5=99=A8=E4=BC=A0=E5=8F=82'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...66\345\231\250\344\274\240\345\217\202.md" | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 "\351\231\206\346\245\232\347\233\210/20241122\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" diff --git "a/\351\231\206\346\245\232\347\233\210/20241122\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" "b/\351\231\206\346\245\232\347\233\210/20241122\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" new file mode 100644 index 0000000..90916b9 --- /dev/null +++ "b/\351\231\206\346\245\232\347\233\210/20241122\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" @@ -0,0 +1,122 @@ +# MVC练习 +## 第一题 +``` +dotnet new mvc +``` +## 第二题 +``` +dotnet new mvc -o Blog +``` +## 第三题 +``` +dotnet new mvc -o Blog +cd Blog +``` +## 第四题 +``` +dotnet new mvc -o 项目名称 +``` +## 第五题 +``` +dotnet new mvc -o Blog +cd Blog +``` +## 第六题 +``` +mkdir 解决方案名称 +cd 解决方案名称 + +dotnet new sln -n 解决方案文件名称 + +dotnet new mvc -n mvc项目 +dotnet sln add mvc项目 + +dotnet new classlib -n 综合项目1 +dotnet sln add 综合项目1 +dotnet new classlib -n 综合项目2 +dotnet sln add 综合项目2 +dotnet new classlib -n 综合项目3 +dotnet sln add 综合项目3 +``` +## 第七题 +``` + public IActionResult Ok() + { + return View(); + } +``` +## 第八题 +``` +public class BlogsController : Controller + { + public IActionResult Index() + { + return View(); + } + } + +``` +# 控制器传参 +## 1 +``` + public IActionResult Index(int Id) + { + return Content(Id.ToString) + } +``` +## 2 +``` + public IActionResult Index_2(string Id){ + return Content(Id) + } +``` +## 3 +``` + public IActionResult Index_2(string name){ + return Content(name) + } +``` +## 4 +``` + public class BlogContriller : Controller{ + [HttpPost] + public IActionResult Create([FromBody] BlogCreateDto blogCreateDto){ + return Content(blogCreateDto.Title) + } + } + public class BlogCreateDto{ + // Title等为自动属性 + public string Title{get;set;}=null!; + public string Author{get;set;}=null!; + public string Content{get;set;}=null!; + } + +``` +## 5 +``` + public class BlogContriller : Controller{ + [HttpPost] + public IActionResult Create([FromBody] Products productCreateDto){ + return Content(blogCreateDto.Title) + } + } + public class Products{ + public string Name{get;set;}=null!; + public string Price{get;set;}=null!; + public string Stock{get;set;}=null!; + } +``` +## 6 +``` + public class BlogContriller : Controller{ + [HttpPost] + public IActionResult Create_2([FromBody] Students studentCreateDto){ + return Content(blogCreateDto.Title) + } + } + public class Students{ + public string Name{get;set;}=null!; + public string Price{get;set;}=null!; + public string Stock{get;set;}=null!; + } +``` -- Gitee