Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

asp.net mvc - Ambient values in mvc2.net routing

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() }
);

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>

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.

I understand that my action method is after docid and changing it would not clear the docid.

My question here is, can I remove docid in this scenario without changing the route?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have the same "not clearing out" value problem...

I've stepped into source code and I don't understand the reason for being of segment commented as : // Add all current values that aren't in the URL at all

@ SystemWebRoutingParsedRoute.cs, public BoundUrl Bind(RouteValueDictionary currentValues, RouteValueDictionary values, RouteValueDictionary defaultValues, RouteValueDictionary constraints) method from line 91 to line 100

While the clearing process is correctly handled in method preceding steps, this code "reinjects" the undesired parameter into acceptedValues dictionary!?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...