Problem with Html.ActionLink does not include parameters (MVC3)

I have a problem with Html.ActionLink not giving me the link I was expecting.

Here is my route:

routes.MapRoute( "KnownCustomer", // Route name "{controller}/{action}/{custId}/{projId}", // URL with parameters new { controller = "Home", action = "Index" }, // Parameter defaults new { custId = @"\d+", projId = @"\d+" } ); 

Here is my call to Html.ActionLink () "

 @Html.ActionLink("Create New", "Create", "Conflict") 

Here is the URL of the page on which ActionLink exists: http: // localhost: 1283 / Conflict / Index / 1200/300 Here is the result of calling the above Html.ActionLink () http: // localhost: 1283 / Conflict / Create

Should the call include other route parameters? What I was expecting was http: // localhost: 1283 / Conflict / Create / 1200/300

Do I need to pass custId and projId to the view and use overloading to manually deliver values?

+7
source share
1 answer

You did not indicate that the link to the action should have any parameters, in this case it is the direct URL of the action. You need to enable the parameters, i.e.

 @Html.ActionLink("Create New", "Create", "Conflict", new { custID = Model.custID, projID = Model.projID }, null) 
+11
source

All Articles