2009-11-02 58 views
1

對於下面的控制器,爲什麼http://localhost:port/content/about的調用不會傳遞「about」作爲索引控制器的頁面參數的值?默認路由。顯然我不明白路由...如何更改mvc動態頁面路由URL - 爲什麼這不起作用?

public class ContentController : Controller 
    { 
     private IContentService _service; 

     public ContentController() 
      { 
       _service = new ContentService(new ModelStateWrapper(this.ModelState), new ContentRepository()); 
      } 


     public ActionResult Index(string page) 
     { 
      return RedirectToAction("View", new { p = page }); 
     } 
     public ActionResult Page(string p) 
     {  
      ContentPage contentPage = _service.GetPageContent(site, p); 
      return View(contentPage); 
     } 
} 
+0

請張貼您的路線設置。 – Min 2009-11-02 18:18:34

+0

這是用默認的asp.net mvc install – 2009-11-02 18:20:07

回答

1

默認路由假定您使用以下模式:{action}/{id}。你沒有使用這個。您需要重新聲明路由,以便將所有內容發送到「索引」操作並傳遞「p」參數。

+0

謝謝。我沒有意識到這是它的參數名稱。我認爲這只是第一個通過的東西。 – 2009-11-02 18:40:49

0

你在運行IIS6嗎?如果是這樣,請確保將asp.net isapi dll映射到.mvc擴展名。

上週路由被我殺死,直到我發現這個......

+0

我個人默認它爲.aspx。部署時減少工作量。 – Min 2009-11-02 21:03:24