tags:

views:

30

answers:

1

Hello

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

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

+1  A: 

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.

Craig Stuntz