首先配置路由文件,默认页是第一个路由的配置:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Web.Routing;namespace WebApplication1{ public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "path1", url: "{controller}/{action}/{id}", defaults: new { controller = "Path1", action = "Index", id = UrlParameter.Optional } ); routes.MapRoute( name: "path2", url: "{controller}/{action}/{id}", defaults: new { controller = "Path2", action = "Index", id = UrlParameter.Optional } ); } }}
然后右键项目,添加-搭建基架项。添加控制器和视图。
添加的视图必须位于view目录下,因为它就是路径。可以参考:
访问路径就是:
http://localhost/Path1/Index
http://localhost/Path2/Index
另外,控制器返回视图最好不要返回空,否则会出现奇怪的错误。