问题
I have an mvc app with a DefaultController which maps to index.cshtml so
http://localhost:<port>/Default/Index
works fine. but the default root page:
http://localhost:<port>/
is not mapped to anything. How can I map it to my Default/Index?
Here is my RouteConfig.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MVC5_HttpClientTest_F45
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
回答1:
Change your Default Map route controller to
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional }
);
来源:https://stackoverflow.com/questions/26132022/c-sharp-mvc-how-to-map-the-root-url-to-a-specific-view