.NETCore添加Area .NETCore添加区域Area代码实例解析
叶丶梓轩 人气:0一,如下图
二,构建好框架,将不必要的包删掉
三,添加路由
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"; } } }
加载全部内容