乘风原创程序

  • .NETCore添加区域Area代码实例解析
  • 2020/7/13 11:16:07
  • 一,如下图

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

    三,添加路由

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