开发者

Route with nullable parameter problem

I have a page where you edit "usergroups". And I have this in my controller:

开发者_如何学Go
public ActionResult UsergroupEdit(int? usergroupID)

both edit and create on the same view.

and in global.asa:

 routes.MapRoute("AdminUsergroupEdit", "Admin/Usergroup/Edit/{usergroupID}",
            new
            {
                controller = "UsergroupsAdmin",
                action = "UsergroupEdit"
            }
                );

 routes.MapRoute("AdminUsergroupCreate", "Admin/Usergroup/Edit/",
            new
            {
                controller = "UsergroupsAdmin",
                action = "UsergroupEdit"
            }
                );

And when using this it works:

Html.ActionLink("Edit", "UsergroupEdit", new { usergroupID = Model.Usergroup.UsergroupID })

But this one doesnt match, whats the problem with this one?

Html.ActionLink("Create", "UsergroupEdit")

How can I make it match in both cases? since "UsergroupID" is nullable, but in both cases should match that action?

/M


Use Html.RouteLink instead of Html.ActionLink:

Html.RouteLink("Create", "AdminUsergroupCreate", "Create",
    new RouteValueDictionary { { "action", "UsergroupEdit" } } )

RouteLink is faster and never picks the wrong route.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜