在mvc2.net路由环境值 [英] Ambient values in mvc2.net routing
问题描述
我已经按照登记的两条路线我的的Global.asax
文件
I have following two routes registered in my global.asax
file
routes.MapRoute(
"strict",
"{controller}.mvc/{docid}/{action}/{id}",
new { action = "Index", id = "", docid = "" },
new { docid = @"\d+"}
);
routes.MapRoute(
"default",
"{controller}.mvc/{action}/{id}",
new { action = "Index", id = "" },
new { docConstraint = new DocumentConstraint() }
);
和我有一个静态的仪表板链接,在我的标签栏和从值构建以dB这里一些其他环节是code
and I have a static "dashboard" link in my tabstrip and some other links that are constructed from values in db here is the code
<ul id="globalnav" class = "t-reset t-tabstrip-items">
<li class="bar" id = "dashboard">
<%=Html.ActionLink("dash.board", "Index", pck.Controller, new{docid =string.Empty,id = pck.PkgID }, new { @class = "here" })%>
</li>
<%
foreach (var md in pck.sysModules)
{
%>
<li class="<%=liClass%>">
<%=Html.ActionLink(md.ModuleName, md.ActionName, pck.Controller, new { docid = md.DocumentID}, new { @class = cls })%>
</li>
<%
}
%>
</ul>
现在我下水地址是本地主机/ oa.mvc /指数/ 11
明确匹配二号路线。但是,当我访问已经映射到第一条路,然后回来 dash.board
链接,它显示我本地主机/ oa.mvc / 7的任何页面/指数/ 11
,其中 7
是文档ID
和previous网址采摘。
Now my launching address is localhost/oa.mvc/index/11
clearly matching the 2nd route. But when I visit any page that has mapped to first route and then come back to dash.board
link it shows me localhost/oa.mvc/7/index/11
where 7
is docid
and picked from previous Url.
据我所知,我的操作方法是经过文档ID和改变它不会清除文档ID。
I understand that my action method is after docid and changing it would not clear the docid.
在这里我的问题是:我可以删除文档ID
在这种情况下不改变路线
My question here is: Can I remove docid
in this scenario without changing the route?
问候
阿迪尔
Regards
adeel
推荐答案
我的路由定义是这样的:
My routing is defined this way:
routes.MapRoute(
"Planning",
"Plans/{plan}/{controller}/{action}/{identifier}",
new { controller = "General", action = "Planning", identifier = UrlParameter.Optional },
new { plan = @"^\d+$" }
);
// default application route
routes.MapRoute(
"Default",
"{controller}/{action}/{identifier}",
new {
controller = "General",
action = "Summary",
identifier = UrlParameter.Optional,
plan = string.Empty // mind this default !!!
}
);
这是非常相似,你所使用的。但介意在那里我定义默认我的默认路由。虽然我没有缺省路由定义计划
路线值我还是将它设置为的String.Empty
。所以每当我用 Html.ActionLink()
或 Url.Action()
,我想
This is very similar to what you're using. But mind my default route where I define defaults. Even though my default route doesn't define plan
route value I still set it to string.Empty
. So whenever I use Html.ActionLink()
or Url.Action()
and I want plan
to be removed from the URL I call it the usual way:
Url.Action("Action", "Controller", new { plan = string.Empty });
和计划不包含在URL查询字符串了。自己试试它了它可能正常工作。
And plan is not included in the URL query string any more. Try it out yourself it may work as well.
这篇关于在mvc2.net路由环境值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!