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 牛腩" });}}
}
运行即可看到效果,http://localhost:5056/api/common/getcategory