解决方法如下:
[Route("[controller]/[action]")]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult Test()
{
Response.WriteAsync("aaaaaa123");
return Json(new { name="张三"});
}
}
同时注册 webapi控制器
app.MapControllers();