Get current action and controller and use it as a variable in an Html.ActionLink?

ぃ、小莉子 提交于 2019-12-05 01:27:59

Use ViewContext.RouteData to determine current Controller and Action:

@Html.ActionLink("Spanish Version", 
                 ViewContext.RouteData.Values["action"] as String,
                 ViewContext.RouteData.Values["controller"] as String,
                 new { Area = "es" })

Try this:

 Html.ActionLink("Espanol", "action", "ControllerName", new { Area = "es" }, null)
SiuFay

If the actionName is only for @Html.ActionLink(), you can simply pass "null" as the actionName. The current actionName will be used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!