Serj Sagan
Serj Sagan

Reputation: 30267

parameter only in url

I trying to achieve a URL of

http://www.dgcportal.com/Services

I am using this in my RegisterRoutes method:

routes.MapRoute(
                name: "Categories",
                url: "{categoryName}",
                defaults: new { controller = "Home", action = "Index", categoryName = UrlParameter.Optional }
            );

my action link is:

@Html.ActionLink(category.Name, "", "", new  { categoryName = category.Name }, null)

however, this gives me a url of .../?categoryName=Services

How can I achieve the desired effect? I can not have my controller be called Services as that is dynamically generated. I can see the obvious flaw in my route definition (how will it route to other controllers?) Is such a route not possible in MVC 4?

Upvotes: 0

Views: 57

Answers (2)

tia
tia

Reputation: 9708

Does this overload work?

http://msdn.microsoft.com/en-us/library/dd504972(v=vs.108).aspx

Put controller and action name in and it should work I think.

Upvotes: 0

fcuesta
fcuesta

Reputation: 4520

Your map route seems correct, but I think you should use RouteLink instead of ActionLink to generate your link:

@Html.RouteLink(category.Name, "Categories", new  { categoryName = category.Name })

Upvotes: 1

Related Questions