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 牛腩" }); } } }
标签:WebApi,建立,项目,api,Blazor,public From: https://www.cnblogs.com/niunan/p/18396200