c# - ASP.NET MVC 3 - Edge case with Routing in Area -
i have page user's can "ask question" against product.
the route is:
context.maproute( "q&a - ask - product", "{someproducturi}/questions/ask", new { controller = "questions", action = "ask" } );
which matches:
/car/questions/ask
/phone/questions/ask
here's action:
public class questionscontroller : controller { public viewresult ask(string someproducturi) { // ... } }
now, problem is, need allow user select product on page itself, e.g no product pre-chosen in uri.
because controller in area, "default url" this:
/myarea/questions/ask
so what's happening is, when action, "someproducturi" set "myarea", causing sorts of grief.
i want re-use same action/view both sets of url's, don't want route value set "myarea" when it's default url.
hope makes sense - ideas?
do need seperate route? can add route constraint "someproducturi" can't "myarea", doesn't match route , falls default?
i have many routes, didn't want add edge case.
so ended using route constraint:
public class notequaltoareaname : irouteconstraint { public bool match(httpcontextbase httpcontext, route route, string parametername, routevaluedictionary values, routedirection routedirection) { return string.compare(values[parametername].tostring(), route.datatokens["area"].tostring(), true) != 0; } }
pretty simple, , generic - can re-use anytime come across type of edge case.
Comments
Post a Comment