2
votes

I have a TextObject controller, which is meant to be accessed by "~/umt/text/{action}/{id?}", as defined in the controller using attribute routing, but the action link:

@Html.ActionLink("Index", "Index", "TextObject")

ignores Attribute Routing and uses the Conventional routing definitions, producing ~/TextObject/ instead of the desired ~/umt/text/

the TextObjectController:

[Authorize]
[RouteArea("umt")]
[RoutePrefix("text")]
[Route("{action=index}/{id?}")]
public class TextObjectController : Controller
{
   .....
    public async Task<ActionResult> Index()
    {
        return View(await db.TextObjects.ToListAsync());
    }
   .....
}

My route config:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        //Enable Attribute Routing
        routes.MapMvcAttributeRoutes();

        AreaRegistration.RegisterAllAreas();

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

Is there any additional configuration required on the controller to make the action link work or does it not work with attribute routing?

I'd like to keep it simple, and it routes correctly going directly through the url, but the ActionLink helper seems to not like something about it.

1

1 Answers

0
votes

I can't see that you specify your defauld area it RouteConfig so your action link should look like:

@Html.ActionLink("TextObject", "Index", "Index", new { area = "umt" }, null)