發(fā)表日期:2019-04 文章編輯:小燈 瀏覽次數(shù):3511
我們通過*Route.config配置自定義文件時(shí),模板中可能會用到url中的一些節(jié)點(diǎn),下面這段配置一個(gè)自定義搜索頁面
?<route?urlConstraint="^search/([1-9]\d{0,8}/)?$"??viewPath="搜索/search.cshtml"?httpcacheSolutionId="0"?columnId="0"?title="搜索"></route>其中([1-9]\d{0,8}/)?匹配分頁規(guī)則。
比如我們搜索頁面是:http://www.pageadmin.net/search/2/?kw=關(guān)鍵詞
那么模板中如何獲取到2這個(gè)分頁呢,自定義文件系統(tǒng)預(yù)設(shè)了一個(gè)ViewBag.CustomRouteParameter(類型為字符串?dāng)?shù)組)來保存url節(jié)點(diǎn),使用方法如下:
@{
????????string?kw=Request.QueryString["kw"];//獲取kw參數(shù)
????????int?currentPage?=?1;
????????string[]?customRouteParameter?=?ViewBag.CustomRouteParameter;
????????if?(customRouteParameter.Length?>?1)
????????{
????????????currentPage?=?int.Parse(customRouteParameter[1]);?//等到2,customRouteParameter[0]得到search
????????}
}