mvc routing重新
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MyMvc
{
// 注意: 有关启用 IIS6 或 IIS7 经典模式的说明,
// 请访问 http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
/*routes.MapRoute(
"Default", // 路由名称
"{controller}/{action}/{id}", // 带有参数的 URL
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
);
*/
routes.MapRoute(
"Default1",
"{controller}/{action}/{id}/{sid}",
new{controller = "Home",action = "Index",id = UrlParameter.Optional,sid = UrlParameter.Optional}
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
}
}
http://localhost/home/index/123/321时,controller="Home", action="Index", id=123, sid=321。如果URL不带可选参数
http://localhost/home/index,这时controller="Home", action="Index", id和sid为空。

浙公网安备 33010602011771号