I can have URL in more formats:
site.net/Controller/Function/AnyStringProperty
site.net/Controller/Function/AnyIntProperty
site.net/Controller/Function/AnyStringProperty/AnyIntProperty
In controller i can write any logic for Property1 and Property2, but it seems like dirty way.
Other way is write something like site.net/Controller/Function/AnyDefautlForStringProperty/AnyIntProperty
except
site.net/Controller/Function/AnyIntProperty
Is any possibility how to do this in routes.MapRoute function? Or in other place then in co开发者_如何转开发ntroller?
routes.MapRoute(
"Controller/Function",
"Controller/Function/{AnyStringProperty}/{AnyIntProperty},
new { controller = "Controller", action = "Function", AnyStringProperty = "", AnyIntProperty = ""}
);
Yes, you can do that.
Here's what I've used in the past:
context.MapRoute(
"default_sub_resource",
"prefix/{controller}/{resource}/{subresource}/{action}"
)
context.MapRoute(
"default_resource",
"prefix/{controller}/{resource}/{action}"
)
context.MapRoute(
"default",
"prefix/{controller}/{action}"
)
I inlcuded the paramters before the action, but you can put them where-ever you like.
精彩评论