Вопрос

How do I change the following code to produce the proper URL?

Note: The ActionLink is being produced from a different controller than DomainsController.

@Html.ActionLink("Domains", "Index", "Domains", new { id = item.Name }, null)

The goal is to see the following URL.

/Domains/ItemName

What I'm getting is:

/Domains/Index/ItemName

Any help is greatly appreciated.

Это было полезно?

Решение

Strange routing :)

Here goes quick and dirty solution:

@{string link= "Domains/" + item.Name;}
@Html.ActionLink("Domains", "", link, null, null)

Другие советы

Your requirement is little impractical. You certainly can achieve that with something like

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

But then, you would have to create explicit routing rules for all of the other DomainsController action methods, otherwise you wouldn't be able to use simply e.g. /Domains/OtherAction anymore - it would be caught by the aforementioned rule and interpreted as a call to the Index method with id == "OtherAction"

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top