步骤(常规方法)
- 新建一个控制器--
LarsController.cs
using Microsoft.AspNetCore.Mvc; namespace Blog.Controller; public class LarsController:Controller -----继承 {public IActionResult Index(){return View();} }
- 获取id
// program.cs中默认值是idpublic IActionResult Index(int id) {return Content(id.ToString()); }
- 获取方法中的name
public class Students {public string name{get;set;}=null!; ----字符串需要=null!public int age{get;set;} }// 在LarsController中 [HttpPost] public IActionResult Create([FromBody]Students stu) {return Content(stu.name); }//[FromBody]传递复杂数据