模板中获取自定义文件的url节点值

2024-03-01 16:53 小编

我们通过*Route.config配置自定义文件时,模板中可能会用到url中的一些节点,下面这段配置一个自定义搜索页面

 <route urlConstraint="^search/([1-9]\d{0,8}/)?$"  viewPath="搜索/search.cshtml" httpcacheSolutionId="0" columnId="0" title="搜索"></route>

其中([1-9]\d{0,8}/)?匹配分页规则。

比如我们搜索页面是:http://www.pageadmin.net/search/2/?kw=关键词

那么模板中如何获取到2这个分页呢,自定义文件系统预设了一个ViewBag.CustomRouteParameter(类型为字符串数组)来保存url节点,使用方法如下:

@{
        string kw=Request.QueryString["kw"];//获取kw参数
        int currentPage = 1;
        string[] customRouteParameter = ViewBag.CustomRouteParameter;
        if (customRouteParameter.Length > 1)
        {
            currentPage = int.Parse(customRouteParameter[1]); //等到2,customRouteParameter[0]得到search
        }
}



在线咨询 拨打电话

电话

13363039260

内部绝密传真282期

微信二维码