[Area("Customer")]
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
return View();
}app.UseMvc(routes =>
{
routes.MapRoute(
name: "areas",
template: "{area:Customer}/{controller=Home}/{action=Index}/{id?}");
});
我创建了as.pnet核心mvc应用程序,创建了客户区,然后将主控制器和主文件夹从控制器和视图移动到客户区内的控制器和视图中,然后在运行应用程序时将路由放入启动文件中。运行应用程序时,会显示一个异常错误,显示:Microsoft.AspNetCore.Routing.RouteCreationException:'An error occurred when the route with name‘area’and template '{area:Customer}/{controller=Home}/{action=Index}/{id?}'.‘问题是什么?我如何解决它?
发布于 2019-09-16 11:24:16
对于area:Customer,这意味着限制区域遵循无效的Customer规则。您可以查看有效约束的Route constraint reference。
如果希望默认区域为Customer,则应将:更改为=,如下所示
routes.MapRoute(
name: "areas",
template: "{area=Customer}/{controller=Home}/{action=Index}/{id?}"
);https://stackoverflow.com/questions/57938222
复制相似问题