I'm trying to understand the behavior within my RouteConfig setup. Here is what I have:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "2KeywordController",
url: "{keyword1}-{keyword2}-{controller}/{action}",
defaults: new { action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" }
);
}
}
I have a controller called ContactController and a View under /Views/Contact/Index.cshtml that has the following to create the form:
@using (Html.BeginForm("Index", "contact", FormMethod.Post, new { id = "contactform" }))
When I navigate to example.com/kw1-kw2-contact the ContactController is correctly called and the default contact view is displayed. When I looked at the source I was surprised to find that the action for the form was set to "/kw1-kw2-contact" instead of just "/contact". Is there a way to use Html.Begin() but have just the controller name appear in action without the two keywords? e.g. /contact