ASP.NET MVC - Get Current Area Name in View or Con

2019-01-06 11:35发布

How do you get the current area name in the view or controller?

Is there anything like ViewContext.RouteData.Values["controller"] for areas?

9条回答
Explosion°爆炸
2楼-- · 2019-01-06 12:02

In ASP.NET Core 1.0 the value is found in

ViewContext.RouteData.Values["area"];

查看更多
霸刀☆藐视天下
3楼-- · 2019-01-06 12:05

In MVC 2 you can use ViewContext.RouteData.DataTokens["area"]

查看更多
别忘想泡老子
4楼-- · 2019-01-06 12:05

I know this is a very very old post but we can use the Values Property exactly the same way as the DataTokens

Url.RequestContext.RouteData.Values["action"] worked for me.

查看更多
登录 后发表回答