How to pass Area in Url.Action?

后端 未结 3 1155
广开言路
广开言路 2020-12-13 11:52

The problem in Html.ActionLink() is that you can\'t add additional html content inside the tag that it generates. For example, if you want to add an icon besides the text l

3条回答
  •  醉梦人生
    2020-12-13 12:37

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

    Also don't forget to add the namespace of the controller to avoid a conflict between the admin area controller names and the site controller names.

    Something like this

     public override void RegisterArea(AreaRegistrationContext context)
            {
                context.MapRoute(
                    "Admin_default",
                    "Admin/{controller}/{action}/{id}",
                    new { action = "Index", id = UrlParameter.Optional },
                      new[] { "Site.Mvc.Areas.Admin.Controllers" }
                );
            }
    

提交回复
热议问题