控制器没有拿起路线

时间:2009-09-10 19:55:09

标签: asp.net-mvc routing

我的路线如下:

  routes.Add(new Route("{companyName}/{action}/{id}", new MvcRouteHandler())
   {
     Defaults = new RouteValueDictionary(new { controller = "CompanyController", action = "Index", id = 1 }),
   }   
   );

我的行动:

  public ActionResult Index(string companyName, string id)
  {
         Response.Write(companyName);
         Response.End();

         return ViePage("~/views/company/index.aspx");
  }

1 个答案:

答案 0 :(得分:2)

试试这个:

 routes.Add(new Route("{companyName}/{action}/{id}", new MvcRouteHandler())
   {
     Defaults = new RouteValueDictionary(new { controller = "Company", action = "Index", id = 1 }),
   }   
   );

在引用您的控制器时,您不希望在那里使用名称的“控制器”部分。