Route with nullable parameter problem
I have a page where you edit "usergroups". And I have this in my controller:
开发者_如何学Gopublic 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.
精彩评论