2009-09-10 41 views
1

我的路线是这样的:控制器不拾取路径

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"); 
    } 

回答

2

试试这个:

routes.Add(new Route("{companyName}/{action}/{id}", new MvcRouteHandler()) 
    { 
    Defaults = new RouteValueDictionary(new { controller = "Company", action = "Index", id = 1 }), 
    } 
    ); 
引用您的控制器时,你不

希望在那里拥有“控制器”部分的名称。

+0

您也不必指定视图页面的实际文件路径。 MVC框架将找到与View/{Controller}/{Action}匹配的视图 – scottm 2009-09-10 20:03:53

+0

Good Point Scott!也。 ViePage不会走得太远。但这可能只是一个错误:) – Patricia 2009-09-10 20:08:14

+0

啊,添加控制器到最后,谢谢Patricia! – mrblah 2009-09-10 20:09:30