【问题标题】:working with Areas in asp.net core在 asp.net 核心中使用区域
【发布时间】:2018-12-17 21:09:28
【问题描述】:

我正在用 asp.net core MVC 建立一个网站。我在其中添加了新区域。现在当我尝试如下使用“redirecttoaction”时:

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

它正在执行操作,但视图未加载。不知道 ASP.NET Core 有什么变化。我不想像下面这样对视图路径进行硬编码:

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

请确认,实现这一目标的正确方法是什么。

【问题讨论】:

    标签: asp.net view asp.net-core-mvc asp.net-mvc-areas


    【解决方案1】:

    我找到并修复了它。如下:

    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();
     }
    }
    

    快乐编码。 :)

    【讨论】:

      猜你喜欢
      • 2017-07-06
      • 1970-01-01
      • 2020-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 2020-06-05
      • 1970-01-01
      相关资源
      最近更新 更多