in one of my asp.net mvc 2 views I am have the following statement
window.location.href = '<% = Url.Action("Index","Feature", new {id=""}) %>/' + $("#ProductId").val();
as can be seen $("#ProductId").val() can only be computed from client action and so outside url.Action
I have my Routes as shown below:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.IgnoreRoute("{*allimages}", new {allimages = @".*\.jpg(/.*)?"});
routes.MapRoute(
"Default", // Route name
"{controller}.mvc/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"DefaultIndex", // Route name
"{controller}.mvc/{id}", // URL with parameters
new { controller = "Home", action = "Index"} // Parameter defaults
);
routes.MapRoute("Root", "", new { controller = "Home", action = "Index", id = "" });
}
The request with Url.Action fails because the route thinks the "action" is the "id"
How can I make sure the route configuration in "DefaultIndex" is validated and the url is
Key >> Value
controller = Feature
action = index
id = 9a1347dc-60b0-4b3b-9570-9ed100b6bc6a
Edit 2
Image 2:
Edit 1- Route Order
I almost thought I solved it by changing the route order
routes.MapRoute(
"DefaultIndex", // Route name
"{controller}.mvc/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}.mvc/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute("Root", "", new { controller = "Home", action = "Index", id = "" });
it did work for http://localhost:61000/Feature.mvc/9a1347dc-60b0-4b3b-9570-9ed100b6bc6a/
but failed for a post on same page
http://localhost:61000/Product.mvc/List
**** History ****
Have been using + $("#ProductId").val(); ="/domainname[virtual directory alias]/Fewature.mvc/Index"+$("#ProductId").val();
always worked, though I had to change all scripts when posted to server domainname[virtual directory alias]/ changes from development to test to production
trying to streamline it:
Had the following statement earlier:
window.location.href = '<% = Url.Action("Index","Feature"}) %>/' + $("#ProductId").val();
Would result in multiple Id values
it maps existing route {id} into Url.Action("Index","Feature"}
resulting in NoMatch
Introduced
new {id=""} to get around it.