2012-07-26 110 views
3

我有我的看法如下代碼:剃刀Html.ActionLink參數

@Html.ActionLink(item.Title, "Articles/Details", New With {.id = item.ArticleId}) 

它產生以下鏈接:

/博客/條/詳細信息/ 1

我想讓它產生這個,而不是:

/文章/細節/ 1

我試圖搞亂參數,但我不知道如何使它做我想做的。我怎樣才能做到這一點?謝謝。

回答

6

使用此overload

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper, 
    string linkText, 
    string actionName, 
    string controllerName, 
    Object routeValues, 
    Object htmlAttributes 
) 

所以,你的代碼可以這樣寫

@Html.ActionLink(item.Title, "Details","Article", 
        New With {.id = item.ArticleId},Nothing) 

檢查this msdn page看到所有可用的重載

+0

謝謝你,這個工程。這個例子中的「Nothing」是什麼?請告訴我在哪裏可以找到一個完整的參數列表,如:Html.ActionLink(標題, WhateverThisParamIs等) – user1477388 2012-07-26 18:36:10

+0

@ user1477388:這意味着我們將Nothing作爲HTMLAttributes傳遞。如果你想傳遞一些客戶的HTML屬性(CSS類),你可以用Nothing替換Nothing。檢查我更新的答案。 – Shyju 2012-07-26 18:38:59

+0

好的答案,但我注意到,如果我沒有通過「無」,它就不起作用。我將不得不記住這一點。 – user1477388 2012-07-26 18:44:42