2010-02-09 24 views
3

我不確定從哪裏開始在MVC項目中實現選項卡。這是問題。我想要在部分視圖中實現選項卡,但我希望選項卡可用於我的所有控制器和視圖。當我編碼標籤我需要知道當前的控制器和視圖,所以我可以使用選項卡QueryString修改Html.ActionLink()。如何實現ASP中的分部視圖中的選項卡MVC

我怎麼可能會去這

<%= Html.ActionLink(QuestionSort.SortArray[0], "Current View", "Current Controller", null, new { rel = "nofollow" })%>&nbsp;&nbsp; 
<% for (int x = 1; x < QuestionSort.SortArray.Length; x++) 
{ %> 
    <%= Html.ActionLink(QuestionSort.SortArray[x], "Current View", "Current Controller", new { sort = Server.UrlEncode(QuestionSort.SortArray[x]) }, new { rel = "nofollow" })%>&nbsp;&nbsp;  
<% } %> 

回答

2

你可以從ViewContext路由值電流控制器。

我建議,因爲你可以把一些代碼到這個爲了工作說出來,你可能想要寫一個方法的HtmlHelper生成一些HTML的位置 - 但是:

<%= this.ViewContext.RouteData.Values["controller"] %> 

將打印出來的控制器名稱

<%= this.ViewContext.RouteData.Values["action"] % 

行動

它應該很簡單,從這個數據構建一個上下文感知菜單

相關問題