Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify default Area without adding area = "" to every ActionLink

I have a large existing application built on ASP.NET MVC2 RC2.

All of my links look like this: htp//site/controller/action/id

I just added an Area called: BigBird.

Now when I'm in the BigBird area, all of my links look like this: htp://site/BigBird/controller/action/id

Problem is that none of those controllers/actions exist in my new Area. So I have to go through all of my actionlinks all over my application and put this routevalue: area = string.empty

Is there any way around this?

like image 916
iamwill Avatar asked Feb 26 '10 22:02

iamwill


People also ask

How do you define area in URL action?

You can use this Url. Action("actionName", "controllerName", new { Area = "areaName" });

What is area routing?

The routing area, abbreviated as RA, is the counterpart of the location area (LA) in packet-switched (PA) networks. The RA is usually a smaller area compared to the LA because using multimedia services requires more frequent paging messages.

How do you pass an ActionLink model?

The Lookup method's arguments match the named properties in the ActionLink. MVC4 allows you to pass the model automatically through URL variables, which is seen my second example. The docs for ActionLink show that none of that method's overloads accepts a viewmodel object.

How will you localize URL in MVC application?

To offer a website in multiple languages using ASP.Net we simply need to add some resource. resx files to our project and voilà. Based on the language of the browser, IIS will match the localization resource.


1 Answers

I don't know of away around it if you are using the standard MVC methods (other than maybe overriding them to call your own version), but if you are using the ActionLink<TController> or other generic methods provided in the MvcFutures lib then you can.

The MvcFutures methods call ExpressionHelper.GetRouteValuesFromExpression(), which looks for an ActionLinkAreaAttribute on the controller to determine the area. So you can decorate your controllers in your main "area" as follows:

[ActionLinkArea("")]
[HandleError]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

The action links should be generated correctly using the standard syntax:

<%= Html.ActionLink<HomeController>(c => c.Index(), "Home") %>
like image 107
Eric Amodio Avatar answered Jan 01 '23 22:01

Eric Amodio