翟塘峡口曲江头,万里风烟接素秋。那遍地的绿草,那微风中轻轻摇曳的芦苇,那栖满了夜鹭的灌木丛,就像一幅立体的田园画,静静地展现在我的眼前。
一,如下图
二,构建好框架,将不必要的包删掉
三,添加路由
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapAreaControllerRoute(
name: "areas", "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
});
四,添加控制器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace NLD.HouTai.Areas.Api.Controllers
{
[ApiController]
[Area("API")]
[Route("API/[controller]/[action]")]
public class UserController : ControllerBase
{
[HttpGet]
public string Get()
{
return "Get";
}
}
}
到此这篇关于.NETCore添加区域Area代码实例解析就介绍到这了。成功等于百分之一的灵感加上百分之九十九的汗水。更多相关.NETCore添加区域Area代码实例解析内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!