Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem With Html.ActionLink Not Including Parameters (MVC3)

I am having an issue 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 that the ActionLink exists on: http://localhost:1283/Conflict/Index/1200/300 Here is the result of the call to the above Html.ActionLink() http://localhost:1283/Conflict/Create

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

Do I need to pass the custId and projId in to the View and use an overload to supply the values manually?

like image 850
Dean Avatar asked Dec 17 '10 16:12

Dean


1 Answers

You've not specified that the action link should have any parameters, in that case it's a straight URL to the action. You need to include the parameters, i.e.

@Html.ActionLink("Create New", "Create", "Conflict", new { custID = Model.custID, projID  = Model.projID }, null)
like image 148
Lazarus Avatar answered Oct 13 '22 09:10

Lazarus