From 36f2ba9a9ee0a259cd209b391ecdba7c235112c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E4=BD=B3=E6=AC=A3?= <14091193+fanjxin@user.noreply.gitee.com> Date: Wed, 27 Nov 2024 14:07:39 +0800 Subject: [PATCH] =?UTF-8?q?11.25=E7=AC=94=E8=AE=B0=E6=8F=90=E4=BA=A4?= 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" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "\350\214\203\344\275\263\346\254\243/20241125Action \346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" diff --git "a/\350\214\203\344\275\263\346\254\243/20241125Action \346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" "b/\350\214\203\344\275\263\346\254\243/20241125Action \346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" new file mode 100644 index 0000000..4b9aff5 --- /dev/null +++ "b/\350\214\203\344\275\263\346\254\243/20241125Action \346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" @@ -0,0 +1,74 @@ +# 笔记 +## Action的返回值 + (有传参就一定有返回值) + -- 返回常见数据类型:int ,string,Ilist<> + >**ActionResult**:返回相应**状态码**得:200,301,401,404,500 + ``` + 200:请求成功响应正常(也有可能不返回) + 401and404:查找不到资源 + 500:服务端出现内部逻辑问题 + ``` + --视图 + --重定向 + >**ActionResult<>**:可以同时返回**状态码**或者**常规数据** + >**JsonResult** 和**contentResult**:返回响应就是**纯粹的数据** + >**Poco**:可以返回一个对象,而这个对象在被返回的时候,会被**序列化** + 信息--(序列化)网络(反序列化)--信息 + 网络分为(网线,光纤,网络设备) + + **json**:数据在网络中传输的载体 +```cs +public IActionResult Index() +{ + var list = new List + { + new BlogCreateDto + { + Title = "今天下雨", + Author = "今天下雨", + Content = "今天下雨", + }, + new BlogCreateDto + { + Title = "今天下雨", + Author = "今天下雨", + Content = "今天下雨", + }, + new BlogCreateDto + { + Title = "今天下雨", + Author = "今天下雨", + Content = "今天下雨", + }, + }; + return View(); +} +``` +### 重要代码 +``` + public IActionResult Index(){ + // 1.生成随机数 + Random random=new Random(); + // 2.范围[0,100] + int num=random.Next(0,101); + return View(num); + } + public IActionResult Create(){ + // 1.生成随机数 + Random random=new Random(); + // 2.范围(0,100] + int num=random.Next(1,101); + return View(num); + } + public IActionResult Baby(){ + // 1.生成随机数 + Random random=new Random(); + // 2.定一个列表 类型为int + var num=new List(); + for (int i = 0; i <10; i++) + { // 2.范围[5,80] 生成的随机数添加到列表 + num.Add(random.Next(5,81)); + } + return View(num); + } +``` \ No newline at end of file -- Gitee