在MVC下怎么用XML实现breadcrumbs导航栏

发布时间:2021-11-03 18:00:46 作者:小新
来源:亿速云 阅读:106

小编给大家分享一下在MVC下怎么用XML实现breadcrumbs导航栏,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

先看下样子在MVC下怎么用XML实现breadcrumbs导航栏

像这种导航栏(breadcrumbs)在mvc下我们来实现他。我们采用XML来实现这个功能。

1.首先做个准备,我们编写rounting规则(顺便提一句,我们要用到rounting功能,所以规则必须写正确,不然出不来喔)

代码如下

public static void RegisterRoutes(RouteCollection routes)          {              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");              routes.MapRoute(               "inner",                                              // Route name               "resume/test/inner/{action}/{id}",                           // URL with parameters               new { controller = "inner", action = "Index", id = "" }  // Parameter defaults               );              routes.MapRoute(             "test",                                              // Route name             "resume/test/{action}/{id}",                           // URL with parameters             new { controller = "test", action = "Index", id = "" }  // Parameter defaults             );              routes.MapRoute(                  "Default",                                              // Route name                  "{controller}/{action}/{id}",                           // URL with parameters                  new { controller = "Home", action = "Index", id = "" },                  new { controller = "^(?!(test|inner)).*$", action = "^(?!test).*$" }              );            }

我们加了两个规则

/resume/test

和/resume/test/inner

2.编写用到的XML文件,注意是树形结构的

在models写个Navigator.xml

<?<?xml version="1.0" encoding="utf-8" ?> <node Title="首页"  Description="潘峰的网站" Action="Index" Controller="Home">   <node Title="简历" Description="在线简历" Action="Index" Controller="Resume">     <node Title="Test" Description="Test" Action="Index" Controller="test">       <node Title="inner" Description="inner" Action="Index" Controller="inner">       </node>     </node>   </node> </node>

3.编写我们的类文件来实现Navigator

在models写个navigatorHelper.cs

using System;  using System.Collections.Generic;  using System.Linq;  using System.Web;  using System.Xml;  using System.Xml.Linq;  using System.Web.Routing;  using System.Web.Mvc;  using System.IO;  using System.Text;   namespace conansoft.Helpers  {      public static class MenuHelper      {          private static HttpServerUtilityBase Server = null;

看完了这篇文章,相信你对“在MVC下怎么用XML实现breadcrumbs导航栏”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. Scala 在 Spring Boot 下 MVC 的 jackson 相关配置
  2. 在xml中如何实现动画

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

xml mvc

上一篇:Win7系统下cad怎么转高清图片

下一篇:怎么学习并掌握session和cookie

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》