Currently in my project I am using @Url.Action to create links in the href attribute of anchor tags.
for instance:
<a href='@Url.Action("Index", "Home", new { id = 10 })' id="btn">Click</a>
And this works fine, however the URL produced is...
/home/index?id=10
is there a way to return the url
/home/index/10
for SEO and aesthetic purposes? I used an id and number as a placeholder - in the real application it can and will use a string instead (so...
<a href='@Url.Action("Index", "Home", new { name="test" })' id="btn">Click</a>
to return the url
/home/index/test
You need to ensure that the routing is correct. Make sure you have a route like this:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
For your 'real application', as you are using a parameter called name
you will need one looking like this:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{name}",
defaults: new { controller = "Home", action = "Index" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With