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 牛腩" });
}
}
}