From b859f2e41e79a703721a6d36ddffe7ea63dc3fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= <3167389063@qq.com> Date: Sun, 24 Nov 2024 21:29:36 +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 --- .../20241122--\344\274\240\345\217\202.md" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "\345\210\230\346\254\242/20241122--\344\274\240\345\217\202.md" diff --git "a/\345\210\230\346\254\242/20241122--\344\274\240\345\217\202.md" "b/\345\210\230\346\254\242/20241122--\344\274\240\345\217\202.md" new file mode 100644 index 0000000..60a1782 --- /dev/null +++ "b/\345\210\230\346\254\242/20241122--\344\274\240\345\217\202.md" @@ -0,0 +1,73 @@ + +# 准备软件包升级 +- **安装可用更新** +- **自动解决依赖关系** +- **提高系统安全性** +- **保持系统稳定** +- **自动化和一致性** +- **维护软件的兼容性** +- **获取新功能和改进** + +# 更新软件和补丁 +执行命令:`apt upgrade -y` +- **了解这一步的实际用处意义**:确保系统和软件包是最新的,以修复已知的安全漏洞和提升性能。 + +# 传参 + +### 简单传参(单个) +```csharp +public IActionResult Edit(int id){ + return Content(id.ToString()); +} +``` +- 如有多个简单传参形式,则需修改`Program.cs`中的pattern里的值,例如: + ```plaintext + pattern: "{controller=Home}/{action=Index}/{age?}"; + ``` + ```csharp + public IActionResult Edit(int age){ + return Content(age.ToString()); + } + ``` + +### 复杂传参 +#### 第一步 +```csharp +[HttpPost] +public IActionResult Create([FromBody]Students students){ + return Content(JsonSerializer.Serialize(students)); +} +``` +- 该方式需创建视图中创建一个与控制器相对应对视图文件(书写样式时可用),但还是在Postman软件中查看(前提要运行该程序F5)。 + +#### 第二步 +```csharp +// [HttpPost] +public IActionResult Create([FromBody]Students students){ + return View(students); +} +``` +- 需创建一个类,这个类里有属性: + ```csharp + public class Students{ + public string Name{get;set;}=null!; + public string Age{get;set;}=null!; + public string Weight{get;set;}=null!; + public string Height{get;set;}=null!; + } + ``` + +#### 第三步 +- 因该方法在浏览器中无法查看,需到Postman这个软件中查看结果。 + +## 在控制器中构造对象并传递给视图 +```csharp +public IActionResult Index(){ + var students=new Students{ + Name="零零", + Age="33", + Weight="55", + Height="34" + }; + return View(students); +} \ No newline at end of file -- Gitee