代码之家  ›  专栏  ›  技术社区  ›  Ram Singh

使用ASP.NET Core中的区域

  •  0
  • Ram Singh  · 技术社区  · 7 年前

    我正在用asp.net核心mvc构建一个网站。我在里面增加了新的区域。现在,当我尝试使用“重定向操作”时,如下所示:

    return RedirectToAction("Index", "testing", new { area = "Employer" }, null);
    

    它正在命中操作,但视图未加载。不确定ASP.NET Core中对它做了什么更改。我不想将视图路径硬编码如下:

      return View("~/Areas/Employer/Views/testing/Index.cshtml");
    

    请确认,正确的方法是什么。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Ram Singh    7 年前

    我找到并修好了它。如下所示:

    from here

    [Area("Admin")]
    [Route("admin")]
    public class AdminController : Controller
    {
    public AdminController()
    {
        // do stuff
    }
    
    public IActionResult Index()
    {
        return View();
    }
    
    [Route("[action]/{page:int?}")]
    public IActionResult Orders()
    {
        return View();
    }
    
    [Route("[action]")]
    public IActionResult Shop()
    {
        return View();
    }
    
    [Route("[action]/newest")]
    public IActionResult Payments()
    {
        return View();
     }
    }
    

    快乐的编码。:)