I was going to register a route such as below in ASP .NET MVC3:
routes.MapRoute(
"SearchRoute", // Route name
"Report/Search/{code}/{quarter}/{year}/{receivedBegin}/{receivedEnd}/{transactionBegin}/{transactionEnd}/{page}", // URL with parameters
new {
controller = "Report",
action = "Search",
page = UrlParameter.Optional } // Parameter defaults
);
That route will link to this function in a controller named Report:
public ActionResult Search(string code, int? quarter, int? year,
DateTime? receivedBegin, DateTime? receivedEnd,
DateTime? transactionBegin, DateTime? transactionEnd, int? page=1)
I expected that links generated by Html.ActionLink to that function will be generated like:
Report/Search/10/2/2012/04-30-2012/04-01-2012/04-30-2012
When I generate a link using Html.ActionLink, the link generated is as such:
Report/Search?code=100&quarter=2&year=2012&receivedBegin=04-01-2012&receivedEnd=04-30-2012&transactionBegin=04-01-2012&transactionEnd=04-30-2012
What should I do to generate a result as I expected? Thank you.
Update
This is the code I use to create the link:
@Html.ActionLink("First", "Search", new {
code = currentCode,
quarter = currentQuarter,
year = currentYear,
receivedBegin = currentReceivedBegin,
receivedEnd = currentReceivedEnd,
transactionBegin = currentTransactionBegin,
transactionEnd = currentTransactionEnd }, null).
Yes. The rules in your
RegisterRoutesmethod ofglobal.asaxshould go from top to bottom in order of specificity, therefore this route should definitely be at (or at least near) the top.The default route should always be the last one.