How to correctly use Html.ActionLink with ASP.NET MVC 4 Areas

后端 未结 4 925
野的像风
野的像风 2021-02-01 01:30

I recently discovered Areas in ASP.NET MVC 4, which I have successfully implemented, but I\'m running into troubles with the @Html.ActionLink helper in my Razor vie

4条回答
  •  别那么骄傲
    2021-02-01 02:07

    Just to add up my bit:
    Remember, you're gonna need to have at least 2 areas in your MVC application to get the routeValues: { area="" } working; otherwise the area value will be used as a query-string parameter and you link will look like this: /?area=

    If you don't have at least 2 areas, you can fix this behavior by:
    1. editing the default route in RouteConfig.cs like this:

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

    OR
    2. Adding a dummy area to your MVC project.

提交回复
热议问题