首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web Service >

MVC路由有关问题

2012-04-01 
MVC路由问题[size14px][size12px]C# code注册路由:[size12px][/size]public static void RegisterRoute

MVC路由问题
[size=14px][size=12px]

C# code
注册路由:[size=12px][/size]public static void RegisterRoutes(RouteCollection routes)        {            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");            routes.MapRoute(                "default", // Route name                "{controller}/{action}/{id}", // URL with parameters                new { controller = "Home", action = "index", id = UrlParameter.Optional } // Parameter defaults            );            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");            routes.MapRoute(                "Announce",      // Route name                  "{controller}/{action}/{name}", // URL with parameters                new { controller = "Announce", action = "Index", name = "" }  // Parameter defaults           );        }action:  public ActionResult Index()  {            return Redirect("http://www.baidu.com");  }请求 http://localhost:6389/Announce/List/2 找不到文件
[/size][/size]

[解决办法]
controller" Announce "里加了
public void List(int id)
{
}

这个方法吗?
[解决办法]
routes.MapRoute(
"Announce", // Route name
"{controller}/{action}/{name}", // URL with parameters
new { controller = "Announce", action = "Index", name = "" } // Parameter defaults
);
自己配置的路由放在default的上面 路由解析规则是从上往下解析的
[解决办法]
controller"Announce"里
public void List(int id)
{
}

public void List(int name){}
[解决办法]
你换个顺序试试啊 
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "index", id = UrlParameter.Optional } // Parameter defaults
);
}

[解决办法]
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "index", id = UrlParameter.Optional } // Parameter defaults
);
}

[解决办法]
public static void RegisterRoutes(RouteCollection routes)
{ routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"Announce", // Route name
"{controller}/{action}/{name}", // URL with parameters
new { controller = "Announce", action = "Index", name = "" } // Parameter defaults
);

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"default", // Route name


"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "index", id = UrlParameter.Optional } // Parameter defaults
);
}

热点排行