T4MVC @Url.Action(MVC.Controller.Action()) Renders “?Area=” Parameter in QueryString

后端 未结 2 1698
眼角桃花
眼角桃花 2020-12-14 08:20

I am rendering a menu from a Partial Action directly to the layout, using:

@Html.Action(MVC.Menu.Index())

This action, determines which Men

相关标签:
2条回答
  • 2020-12-14 08:50

    Something strange is going on here, and I wonder if there is some kind of MVC bug at the root. Even without using T4MVC, this happens if you write:

    @Html.ActionLink("Welcome", "Index", "Home", new { Area = "" }, null)
    

    In a regular view, this doesn't generate the bogus ?Area=, while in a Html.Action call it does. I need to ask someone on the team.

    For now, you can workaround by deleting this line (around line 310) in t4mvc.tt:

    <# if (MvcVersion >= 2) { #>result.RouteValueDictionary.Add("Area", area ?? "");<# } #> 
    
    0 讨论(0)
  • 2020-12-14 08:50

    I solve this issue in a very easy way, simply by adding to all routes that are not in area empty area route like this:

    routes.MapRoute(
    "Default",
    "{controller}/{action}/{i​d}",
    new { controller = "Home", action = "Index", area = "", id = UrlParameter.Optional });
    
    0 讨论(0)
提交回复
热议问题