开发者

How to implement tabs in a partial view in ASP MVC

开发者 https://www.devze.com 2022-12-19 09:55 出处:网络
I am not sure where to start to implement tabs in a MVC project. Here is the problem. I want to implement tabs in a partial view but I want the tabs to be available to all my controllers and views. Wh

I am not sure where to start to implement tabs in a MVC project. Here is the problem. I want to implement tabs in a partial view but I want the tabs to be available to all my controllers and views. When I am coding the tabs I will need to know the current controller and view so I 开发者_开发技巧can modify the Html.ActionLink() with the tab QueryString.

How might I go about this

<%= 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;    
<% } %>


You can get the current controller from the ViewContext route values.

I would recommend that because you'll be putting some code into this in order to work that out, that you might want to write an HtmlHelper method to generate some of your HTML here - however:

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

Would print out the controller name

and

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

The action

It should be simple enough to build a context aware menu from this data

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号