I am facing a issue in my current project where I want to display custom URl for my pages. I have tried lot of techniques but none of them fulfills my requirement. I want URL like this:
http://www.anyDomain.com/What-Is-Your-Name
Currently, I am able to set the URL like this:
http://www.anyDomain.com/What-Is-Your-Name?Id=1
I want to ignore Querystring from URL. So that Controller can identify the request & respond accordingly.
Here, Id
is used to fetch details from Database. How can I pass the Parameter Value from View
to Controller
so It can identify the request without adding it in URL?
My Controller
[Route("~/{CategoryName}")]
public ActionResult PropertyDetails(int Id)
{
}
RouteConfig
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}",
defaults:
new
{
controller = "Home",
action = "Index",
}
);
My View
<a href="@Url.Action("PropertyDetails", "Home", new {@Id=item.ID,@CategoryName = Item.Title })">
I just Noticed, I want URL like StackOverflow is using
http://stackoverflow.com/questions/43774917/wordpress-blog-type-permalink-in-mvccustom-url-routing