Try the following:
// Sample URL: /Fixtures/Team/id routes.MapRoute( "Fixtures-by-TeamID", "Fixtures/Team/{teamId}", new { controller = "Fixtures", action = "Team", teamId = -1 } );
your controller should look like this:
public class FixturesController : BaseController // or whatever { /*...*/ public ActionResult Team(int teamId) { return View("Detail", Team.GetTeamById(teamId)) // or whatever } /*...*/ }
And your link will look like
<%= Html.ActionLink("Click here for the team details", "Team", "Fixtures", new { teamId = ViewModel.Data.Id }) %>
(I do not have MVC on this machine, so all of this from memory may have a syntax error or some arguments change).
Note that the route map route matches your 1) controller, 2) step 3) the name of the argument. I found the default action (the third argument in MapRoute) works, while I have never seen your overload of this method before (it may be a delay from the previous version).
Also observe how your FixturesController matches the path (Fixtures) and matches the name of the action (Team), and also matches the argument (teamId).
Finally, the last ActionLink argument should match your controller arguments in the name (teamId) and type.
Its a little too “magical” at the moment (there LOTS string comparisons are happening in the background!). I hope this improves over time. The old Expression style was much better. You essentially named the method you want to run with the values ​​you wanted to pass. I hope they bring this style of expression back into the frame. Haak?
source share