0

I have the following which show the navigation path of the user inside my _layout share view:-

<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>

but i have the following two questions:-

  1. Is using ViewContext.Controller.ValueProvider.GetValue("controller").RawValue the right way to get the controller name

  2. how i can build the href of the a links to point to the required path ?

Regards

4

1 回答 1

2

您可以使用以下命令获取控制器名称RouteData

var controller = ViewContext.RouteData.Values["Controller"].ToString();

然后,您可以像这样构建一个ActionLink

@Html.ActionLink("Click me", "View", controller)
于 2013-07-04T16:09:22.153 回答