'How to avoid HOME in the url an show only the view name?
Is there a way to avoid showing Home in the URL and only the name of the view?
I mean if I want to open the view About which is in the Home controller my URL will be like this:www.website.com/Home/About
But I would love to show onlywww.website.com/About
How can I do this?
Solution 1:[1]
You need to update your route configuration for the Home controller. If you're using Attribute-based routing with the following your Route configuration:
routes.MapMvcAttributeRoutes();
You can do the following in your Home controller:
// GET: Home
[Route("")]
public ActionResult Index()
{
ViewBag.Title = "Home Page";
return View();
}
[Route("about")]
public ActionResult About()
{
ViewBag.Title = "About Page";
ViewBag.Message = "About Us";
return View();
}
That will then remove the controller name from the URLs as required.
Solution 2:[2]
You should then create a controller called 'About'.
Create inside Controller About -> Action "Index".
Copy the content from Home/About to About/Index.
If you want to go to more complicated way and it is not highly recommended (according to this discussion ) please see this solution
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zhaph - Ben Duguid |
| Solution 2 | Zhaph - Ben Duguid |
