2011-12-13 103 views
1

我想使它成为可能,所以如果有人试图去/内容他们被发送到一个specfic控制器(在这种情况下,内容,然后在url中的以下细节传递如MVC3路由到具有参数的特定控制器

参数的URL是http://localhost:51118/content/1/7/test.html

我曾尝试:

routes.MapRoute("content", "content", new { controller = "Content", action = "Index", id = UrlParameter.Optional }); 

我尝试整合CMS这就是为什么网址是它是什么

编辑:

public class ContentController : Controller 
{  
     public ActionResult Index() 
     { 
      var model = new Content();  
      return View(model); 
     } 
} 

回答

2

你的路线是不正确的。只有当您访问http://localhost:51118/content网址时,您才会被路由到内容控制器。如果你想指定更多的paramateres,你应该添加更多的路段。 routes.MapRoute("content", "content/{id1}/{id2}/{content}", new { controller = "Content", action = "Index"});

 

public class ContentController : Controller 
{  
     public ActionResult Index(int id1, int id2, string content) 
     { 
      var model = new Content();  
      return View(model); 
     } 
} 
+0

我该如何在控制器上获取ID? – Beginner

+0

感谢它的魅力 – Beginner

相关问题