.NETCore添加区域Area代码实例解析

这篇文章主要介绍了.NETCore添加区域Area代码实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

一,如下图

.NETCore添加区域Area代码实例解析

二,构建好框架,将不必要的包删掉

.NETCore添加区域Area代码实例解析

三,添加路由

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"; } } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/d556fb4ee5f644077d3ccbf5fd05110d.html