【发布时间】:2015-08-14 17:39:03
【问题描述】:
假设我的 MVC 应用中有这个主控制器:
[RouteArea("Blog")]
public class PageController : BaseAppController
{
}
[RouteArea]
// Called on mydomain/Blog
// and also called on mydomain/
public class BaseAppController : Controller
{
[Route]
public ActionResult Index()
{
return Content("this is the index file form the main controller");
}
}
正如预期的那样,我将在mydomain/Blog 上获得Index 操作,但由于某种原因,我也在我的/ 中获得它,它与我从另一个控制器获得的另一个视图相冲突。
我没有为我的任何根设置任何默认设置:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.LowercaseUrls = true;
routes.MapMvcAttributeRoutes(new CustomDirectRouteProvider());
}
知道有什么问题吗?
【问题讨论】:
-
什么是 CustomDirectRouteProvider?
-
@AlexArt。那是为了启用控制器继承。在这里查看:stackoverflow.com/questions/19989023/…
-
@Hooman - 根据该答案下方的 cmets,许多人无法使其正常工作。此外,答案是针对 WebAPI,而不是针对 MVC。
-
@NightOwl888 谢谢,但事实并非如此。请查看答案
标签: asp.net-mvc model-view-controller routing