2

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 only
www.website.com/About

How can I do this?

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
Tamil Cantroz
  • 125
  • 2
  • 11

2 Answers2

0
  1. You should then create a controller called 'About'.

  2. Create inside Controller About -> Action "Index".

  3. 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

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
Fadi
  • 585
  • 4
  • 22
0

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.
Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117