2011-12-13 52 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