2

I have an area called Organisations. In this area I have a view with a Url.Action link.

By default, if I just pass the action name, it will call the action in the current controller in the Organisation area.

I have a controller in the controllers folder (not in an area), and I want to call an action in that controller.

Basically, this action will be something that any area can call. What would the best way of achieving this?

If this is totally the wrong way to go about this, then I'm open to suggestions.

Thanks,

EDIT - Here are the routes

Global.asax

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Columns",
            "Columns/Columns/{ID}/{idList}",
            new { controller = "Columns", action = "UserColumnList" }
        );

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Account", action = "Login", id = UrlParameter.Optional } // Parameter defaults
        );

    }

OrganisationsAreaRegistration.cs

public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Organisations_view",
            "Organisations/{id}/View",
            new { controller = "Manage", action = "View" }
        );

        context.MapRoute(
            "Organisations_general",
            "Organisations/{id}/General",
            new { controller = "Manage", action = "General" }
        );

        context.MapRoute(
            "Organisations_addressbook",
            "Organisations/{id}/AddressBook",
            new { controller = "Manage", action = "AddressBook" }
        );

        context.MapRoute(
            "Organisations_departments",
            "Organisations/{id}/Departments",
            new { controller = "Manage", action = "Departments" }
        );

        context.MapRoute(
            "Organisations_people",
            "Organisations/{id}/People",
            new { controller = "Manage", action = "People" }
        );

        context.MapRoute(
            "Organisations_events",
            "Organisations/{id}/Events",
            new { controller = "Manage", action = "Events" }
        );

        context.MapRoute(
            "Organisations_journal",
            "Organisations/{id}/Journal",
            new { controller = "Manage", action = "Journal" }
        );

        context.MapRoute(
            "Organisations_tasks",
            "Organisations/{id}/Tasks",
            new { controller = "Manage", action = "Tasks" }
        );

        context.MapRoute(
            "Organisations_edit",
            "Organisations/{id}/Edit",
            new { controller = "Manage", action = "Edit" }
        );

        context.MapRoute(
           "Organisations_journalnew",
           "Organisations/{id}/{action}",
           new { controller = "Manage" }
       );

        context.MapRoute(
            "Organisations_recent",
            "Organisations/{action}",
            new { controller = "Manage", action = "Index" }
        );

        context.MapRoute(
            "Organisations_default",
            "Organisations/{controller}/{action}/{id}",
            new { controller = "Manage", action = "Index", id = UrlParameter.Optional }
        );


    }

2 Answers 2

3

It's actually quite easy. In Url.Action, just add a blank area value, like so:

@Url.Action("Index", "Home", new { area = "" })

In parsing the link, MVC will recognize that the target is not in an area, and will not use any area routes to generate the link.

Sign up to request clarification or add additional context in comments.

1 Comment

Works a treat, sometimes things are just simple! Thanks.
0

You would need to make a specific route for that controller/action for this to work, and I'd place it above the other routes (unless it's specific enough that other routes won't hit it).

I'd be glad to show you this through code, but we'd need to see your current routes table and the controllers in question.

1 Comment

Thanks George. Routes are added above. At the moment, I have a very nasty method of each area containing the action and then running return RedirectPermanent("~/Columns/UserColumnList");

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.