I am having a problem with MVC-3 generating outbound routes for me.
This is the address of the page on which I am enabled for both scenarios: http: // localhost: 1283 / Conflict / Create / 1200/300
Here are the map routes:
routes.MapRoute( null, // Route name "{controller}/{action}/{custId}/{projId}", // URL with parameters null, // Parameter defaults new { custId = @"\d+", projId = @"\d+" } ); routes.MapRoute( null, // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults );
Scenario 1:
From the controller:
public ActionResult Create(int custId, int projId) { return View(); }
From point of view:
@Html.ActionLink("Back to List", "Index", "Conflict", new { custId = ViewBag.custId, projId = ViewBag.projId }, null)
The resulting link that is being created.
http: // localhost: 1283 / Conflict? custId = 1200 & projId = 300
If I changed the controller code as follows:
public ActionResult Create(int custId, int projId) { ViewBag.custId = custId; ViewBag.projId = projId; return View(); }
I did not make any changes to the view, added only these two lines to the controller and created the following link:
http: // localhost: 1283 / Conflict / Index / 1200/300
What am I missing here? This is a consistent behavior, I was able to reproduce this in other areas of my application. The "solution" is obvious, but my question is: why?