2011-09-10 50 views
1

有人可以告訴我這個ActionLink有什麼問題嗎?問題與@ Html.ActionLink

@Html.ActionLink(posts.Title, "PostDetails", "Blogs", new { id = posts.PostID }) 

我期待這個鏈接去:

http://localhost/Blogs/PostDetails?whateverpassed

而是我看到在Firefox如下:

http://localhost:1815/Home/PostDetails?Length=5

它甚至不會去博客控制器。

+0

做你的路由規則是什麼樣子? –

+0

我正在使用默認的...我不認爲這樣它的goona需要新的路線... –

回答

2

您確定您在調用正確的重載方法嗎? 如果你錯過了一個參數,它會給出不同的含義。

HTML.ActionLink method

http://msdn.microsoft.com/en-us/library/dd505040.aspx

請仔細檢查,如果你缺少一個PARAM。

+0

好吧,該鏈接整理了一切...我必須提供ActionLink中的最後一個參數... @Html。 ActionLink(posts.Title,「PostDetails」,「Blogs」,new {id = posts.PostID},null) –

+2

我經常犯這個錯誤。您的原始代碼使用'routeValues =「Blogs」,htmlAttributes = new {id = posts.PostId}',因爲這是錯誤的超載。 –

1

它與路線值傳遞的方式做,而不是使用:

@Html.ActionLink(posts.Title, "PostDetails", new {Controller="Blogs", id = posts.PostID }) 
+0

thx ...我現在清楚了...並且從你的答案中學到了差異化的方式... –

+0

這仍然是錯誤的...它應該是'new {Controller =「Blogs」,id = posts.PostId }' –

+0

謝謝,你是對的會改變它。 – Turnkey