views:

232

answers:

2

In my MVC app, why does

Return RedirectToAction("Edit", "Forms", New With {.member = "123"})

return

http://localhost:13/Forms/Edit?member=123

insted of

http://localhost:13/Forms/Edit/123

?

And why does

<%=Html.ActionLink("MyLink", "Edit", "Forms", New With {.member = "123"}, Nothing)%>

do the same thing?

+5  A: 

The standard routing is set up to use id as the third parameter. Change "member" to "id" and you will get the route that you expect.

Return RedirectToAction("Edit", "Forms", New With { .id = "123"})
tvanfosson
+6  A: 

As tvanfosson says, "id" is what the default route engine is set to look for. Anything else as the 3rd param and it will be tacted on as a querystring.

Why? Because of this method in your Global.asax:

routes.MapRoute(
 "Default",
 "{controller}/{action}/{id}",
 new { controller = "Home", action = "Index", id = "" }
);

You can change this by adding an additional routes.MapRoute() line, like so:

routes.MapRoute(
 "Default",
 "{controller}/{action}/{id}",
 new { controller = "Home", action = "Index", id = "" }
);

routes.MapRoute(
 "Default2",
 "{controller}/{action}/{member}",
 new { controller = "Home", action = "Index", member = "" }
);
eduncan911