我有一个带有两个参数的动作,但是当调用动作时,参数在 url 中显示为查询字符串,如下所示:
localhost:34795/Verification?DepartmentID=3&SubDepartmentID=2
我知道使用自定义 url 路由我可以将其更改为:
本地主机:34795/验证/3/2
但我无法做到这一点,我将此代码添加到 Globas.asax 但直到“没有结果”
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute( "Blog", // Route name
"Verification/{DepartmentID}/{SubDepartmentID}", // URL with parameters
new { controller = "Verification", action = "Index" } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
//routes.MapRoute(
// "Default", // Route name
// "{controller}/{action}/{id}", // URL with parameters
// new { controller = "TestDetails", action = "GetSubDepartmentID", id = "" } // Parameter defaults
//);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
}
}
我这样做了,但什么也没发生,我做错了什么?