asp.net-mvc – 在ASP.NET MVC中使用控制器和用户控件设置活动选项卡的简单方法?
发布时间:2020-05-28 07:16:31 所属栏目:asp.Net 来源:互联网
导读:如何使用用户界面中突出显示的“当前”标签创建标签式导航? 在MVC之前,我查看了文件路径,并找出哪个标签是currrent.现在这很简单,您可以根据当前控制器分配当前选项卡. 一探究竟 … 大多数工作发生在用户控件中. public partial class AdminNavigation : Vie
|
如何使用用户界面中突出显示的“当前”标签创建标签式导航? 解决方法在MVC之前,我查看了文件路径,并找出哪个标签是currrent.现在这很简单,您可以根据当前控制器分配当前选项卡.一探究竟 … 大多数工作发生在用户控件中. public partial class AdminNavigation : ViewUserControl
{
/// <summary>
/// This hold a collection of controllers and their respective "tabs." Each Tab should have at least one controller in the collection.
/// </summary>
private readonly IDictionary<Type,string> dict = new Dictionary<Type,string>();
public AdminNavigation()
{
dict.Add(typeof(BrandController),"catalog");
dict.Add(typeof(CatalogController),"catalog");
dict.Add(typeof(GroupController),"catalog");
dict.Add(typeof(ItemController),"catalog");
dict.Add(typeof(ConfigurationController),"configuration");
dict.Add(typeof(CustomerController),"customer");
dict.Add(typeof(DashboardController),"dashboard");
dict.Add(typeof(OrderController),"order");
dict.Add(typeof(WebsiteController),"website");
}
protected string SetClass(string linkToCheck)
{
Type controller = ViewContext.Controller.GetType();
// We need to determine if the linkToCheck is equal to the current controller using dict as a Map
string dictValue;
dict.TryGetValue(controller,out dictValue);
if (dictValue == linkToCheck)
{
return "current";
}
return "";
}
}
然后在您的.ascx部分usercontol调用SetClass方法来检查与dict相关的链接.像这样: <li class="<%= SetClass("customer") %>"><%= Html.ActionLink<CustomerController>(c=>c.Index(),"Customers",new{@class="nav_customers"}) %></li>
现在你需要的是CSS来突出显示你当前的标签.有一些不同的方法来做到这一点,但是你可以在这里开始一些想法:http://webdeveloper.econsultant.com/css-menus-navigation-tabs/ <% Html.RenderPartial("AdminNavigation"); %> (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-5 – MVC5中的域路由
- asp.net – MSDeploy.exe可以作为管理员连接,但不能连接任何
- asp.net-mvc-3 – SmtpClient.SendAsync阻止我的ASP.NET MV
- asp.net-mvc-3 – AZURE ACS – Windows Live ID – 如何获
- ASP.NET C#ListBox服务器控件不会禁用
- asp.net-mvc – 如何在DB实体的子模型上使用自定义验证属性
- asp.net – Web部署安装程序(MSI)中没有“IIS 7部署处理程序
- asp.net-mvc-4 – ASP.NET MVC Web Api无法将QueryString映
- asp.net-mvc – 为什么@ Html.AntiForgeryToken()在同一个响
- asp.net-mvc-5 – 我应该如何从JsonResult控制器返回404?
推荐文章
站长推荐
- asp.net – 禁用web.config继承?
- log4Net EventlogAppender不适用于Asp.Net 2.0 W
- asp.net – 可以从Web API访问HttpContext.Curre
- asp.net-core – 如何在IIS上运行ASP.NET MVC6而
- 为什么MVC而不是好的旧ASP.NET?还没有抓住为什么
- ASP.Net将用户数据存储在验证Cookie中
- asp.net – Chrome浏览器不显示HTTP处理程序生成
- ASP.NET Core WebApi将错误消息返回给AngularJS
- asp.net – 将appsettings.production.json发布到
- asp.net – 使用Html.EditorFor生成具有特定行数
热点阅读
