Reputation: 29720
Why doesn't this call to action provide the action method name?
@Url.Action("Index","NewStore")
It just produces...
localhost/TemplateUI/en-CA/Atomic/Wassabi/Store
I need it to produce the /index on the end....
Upvotes: 0
Views: 269
Reputation: 1038780
That's because the Url.Action
helper uses your route registration in Global.asax. And since you are passing Index
as action name I guess that in your route registration you have specified that the default value for action="Index"
, so it is omitted.
For example if you have the following default route:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}",
new { controller = "Home", action = "Index" }
);
}
since the controller = "Home"
and action = "Index"
constraints have been specified both /
and /Home
will be absolutely equivalent urls and invoke the Index
action of Home
controller.
So the same happens when you try to build an url with some of the helpers : it uses your routes.
If you need to have the action name in the url make sure you have removed the action
constraint in your route definition.
Upvotes: 1