-1

I have web in asp.net mvc 4, I have set routes like this

routes.MapRoute(
    name: "CityByAlias",
    url: "kaupunki/{alias}",
    defaults: new { controller = "City", action = "DetailByAlias" },
    namespaces: new string[] { "LepsiMisto.WebSite.Controllers" });

so I can use mysite.com/kaupunki/Kajaany instead of mysite.com/City/Detail/2816.

But if I use razor like this

<a href="@Url.Action("Detail", "Announcement", new { id = announcement.ID })">
    <h3>@announcement.Name</h3>
</a>

user is redirect to mysite.com/City/Detail/2816 How can I set this, like default URL mysite.com/kaupunki/Kajaany? It would be best if user insert mysite.com/City/Detail/2816 to browser and web transform url to mysite.com/kaupunki/Kajaany.

What is the best way to do this?

I apologize for my English, I know it is terrible. Thanks

1 Answers1

0
<a href="@Url.Action("DetailByAlias", "City", new { alias = announcement.Name })">
    <h3>@announcement.Name</h3>
</a>

According to your map, your Action is called DetailByAlias and your Controller is City.

Brad Rem
  • 6,036
  • 2
  • 25
  • 50