开发者

Problem With Html.ActionLink Not Including Parameters (MVC3)

I am having an issue with Html.ActionLink not giving me the link I was expec开发者_StackOverflow中文版ting.

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?


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜