我有以下内容显示了我的_layout共享视图中用户的导航路径: -
<ul class="breadcrumb">
<li>
<a href="#">@ViewContext.Controller.ValueProvider.GetValue("controller").RawValue
</a> <span class="divider">/</span>
</li>
<li>
<a href="#">@ViewContext.Controller.ValueProvider.GetValue("action").RawValue</a>
</li>
</ul>
但我有以下两个问题: -
使用ViewContext.Controller.ValueProvider.GetValue("controller").RawValue
正确的方式获取控制器名称
如何构建指向所需路径的链接的href?
此致
答案 0 :(得分:2)
您可以使用RouteData
:
var controller = ViewContext.RouteData.Values["Controller"].ToString();
然后您可以像这样构建ActionLink:
@Html.ActionLink("Click me", "View", controller)