-3

Possible to shorten the url in routing for mvc?

//FieldController
public ActionResult Field()

//Views
Field

So the URL will be ...Field/Field

is it possible to shorten/remove the end field. So only ...Field

is it something to do with the RegisterRoutes in the Global

eg:
    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Public", action = "Index", id = UrlParameter.Optional } // Parameter defaults
       );
John
  • 3,965
  • 21
  • 77
  • 163
  • 2
    possible duplicate of [Set default action (instead of index) for controller in ASP.NET MVC 3](http://stackoverflow.com/questions/12715667/set-default-action-instead-of-index-for-controller-in-asp-net-mvc-3) – Scorpion Sep 30 '15 at 16:09
  • 1
    Assuming you've read basic [ASP.Net MVC routing](http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/asp-net-mvc-routing-overview-cs) article and including [custom routes](http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/creating-custom-routes-cs) part it is very unclear what your problem is. – Alexei Levenkov Sep 30 '15 at 16:10

2 Answers2

2

Yes. Add a new, explicit route above your controller route.

routes.MapRoute("FieldRoute", "field", new { controller = "FieldController", action = "Field" });

Scorpion
  • 784
  • 7
  • 25
0

Seems to be a duplicate of the following question: Set default action (instead of index) for controller in ASP.NET MVC 3

Based on that the following code should work for you:

routes.MapRoute(
    "Field",
    "Field/{action}",
    new { controller = "Field", action = "Field" }
);

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new {controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
Community
  • 1
  • 1
tyler
  • 59
  • 3