diff --git "a/\347\206\212\345\200\251/20241126-1128\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" "b/\347\206\212\345\200\251/20241126-1128\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..c645867c8ea342e540e49b82d3576c89d45bcada --- /dev/null +++ "b/\347\206\212\345\200\251/20241126-1128\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" @@ -0,0 +1,164 @@ +### 笔记 +1。正向代理和反向代理: 正向代理(Forward Proxy): 正向代理服务器位于客户端和目标服务器之间,客户端通过正向代理服务器访问目标服务器。正向代理服务器可以缓存请求、过滤内容、提供安全性等功能 区别:正向代理:客户端主动发起请求,通过正向代理服务器来访问目标服务器。正向代理服务器就像一个中间人,客户端知道正向代理的存在。 反向代理:客户端发起请求,但请求被反向代理服务器接收,然后反向代理服务器将请求转发到目标服务器。客户端并不知道目标服务器的实际地址,它们只与反向代理服务器通信。 +2。接收view @model 命名空间.类名 @Model.键名 例如: +```html +@model Blog.Controllers.Person; +

渲染(展示)对象数据到视图

+

@Model.Title

+

@Model.Author

+

@Model.Content

+

@Model.Name

+``` +3.定位点 例如: +```html + 编辑 + 删除 + 详情 +``` + +### 作业 +#### 渲染(展示)简单数据类型到视图 +```html + public IActionResult My() + { + string message = "Hello,浣熊千脆面!!"; + return View(message); + } +``` +```html +@model string + + + + + Simple Data Type Rendering + + +

@Model

+ + +``` +#### 渲染(展示)对象数据到视图 +```html +namespace Blog.Models; +public class PersonDto + { + public string Name { get; set; } = null!; + public string Age { get; set; } = null!; + public string City { get; set; } = null!; + } +``` + +```html +using Microsoft.AspNetCore.Mvc; +using Blog.Models; +namespace Blog.Controllers; +public class PersonController : Controller +{ + public ActionResult Index() + { + var person = new PersonDto + { + Name = "浣熊千脆面", + Age = "18", + City = "世 界" + }; + + return View(person); + } +} +``` + +```html +@model Blog.Models.PersonDto + + + + + Object Data Rendering + + +

名片

+

Name: @Model.Name

+

Age: @Model.Age

+

City: @Model.City

+ + +``` + +#### 渲染(展示)集合数据到视图 +```html +public class ProductsController : Controller +{ + public IActionResult List() + { + var products = new List + { + new Product { Id = 1, Name = "产品A", Price = 10.00M }, + new Product { Id = 2, Name = "产品B", Price = 15.50M }, + new Product { Id = 3, Name = "产品C", Price = 20.00M } + }; + + return View(products); + } +} +``` + +```html +@model IEnumerable + +

产品列表

+ +``` +#### 渲染(展示)包含集合数据的对象数据到视图 +```html +public class Category +{ + public int Id { get; set; } + public string Name { get; set; } + public List Products { get; set; } +} +``` + +```html +public class CategoriesController : Controller +{ + public IActionResult Index() + { + var category = new Category + { + Id = 1, + Name = "电子产品", + Products = new List + { + new Product { Id = 1, Name = "手机", Price = 300.00M }, + new Product { Id = 2, Name = "笔记本电脑", Price = 1200.00M } + } + }; + + return View(category); + } +} +``` +```html +@model Category + +

分类: @Model.Name

+
    + @foreach (var product in Model.Products) + { +
  • @product.Name: @product.Price
  • + } +
+``` +#### 尝试构建如下图所示的经典CRUD列表 +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412011631912.png) +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412011632925.png) +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412011632499.png) +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412011632293.png) +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412011632051.png)