0

let's say I have this master controller in my MVC app:

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

as it is expected, I will get that Index action on mydomain/Blog, but for some reason I get it also in my / which it conflicts with another view I have from another controller. I do not have any default set up for any of my roots:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.LowercaseUrls = true;
    routes.MapMvcAttributeRoutes(new CustomDirectRouteProvider());

}

any idea what's the problem?

Yar
  • 7,020
  • 11
  • 49
  • 69
  • What is CustomDirectRouteProvider? – Alex Art. Aug 14 '15 at 17:59
  • @AlexArt. that's there to enable Controller inheritance. check it out here: http://stackoverflow.com/questions/19989023/net-webapi-attribute-routing-and-inheritance – Yar Aug 14 '15 at 18:02
  • @Hooman - According to the comments below that answer, many people are unable to get it working. Also, the answer is for **WebAPI**, not for **MVC**. – NightOwl888 Aug 14 '15 at 18:27
  • @NightOwl888 thanks, but that wasn't the case. check out the answer please – Yar Aug 18 '15 at 16:03

1 Answers1

0

it came up I need to make the base class as abstract since it's in top of the hierarchy, so there wouldn't be any other instance of it accessible by other views. so in above example:

[RouteArea("Blog")]
public class PageController : BaseAppController
{
}

[RouteArea]
// is going to be called just on mydomain/Blog and not on mydomain/
public abstract class BaseAppController : Controller
{
    [Route]
    public ActionResult Index()
    {
        return Content("this is the index file form the main controller");
    }
}
Yar
  • 7,020
  • 11
  • 49
  • 69