Blazor项目中建立WebApi
Blazor项目中建立WebApi
- Program.cs中添加代码:
//第一步 builder.Services.AddControllers(); ..... //第二步 app.MapControllers();
- 创建接口文件
using Microsoft.AspNetCore.Mvc; namespace Niunan.Net.Charge.BlazorWeb.JieKou { [Route("/api/[controller]/[action]")] public class CommonController : Controller { //第三步 [HttpGet] public IActionResult GetCategory() { return Json(new { code = 0, msg = "success", data = "hello 牛腩" }); } } }
撸码:复制、粘贴,拿起键盘就是“干”!!!