2012-04-28 116 views
0

在我的_layout.cshtml我想添加一個像這樣的菜單:如何在_layout.cshtml中傳遞參數actionLink asp.net MVC 3

  • @Html.ActionLink("Profile", "Details", "User", new {e_id ="[email protected]")
  • 我想通過
    @Context.User.Identity.Name
    作爲e_id。我可以通過這種方式?如果不是那麼另一種方式是什麼?當我硬編碼像這樣:
  • @Html.ActionLink("Profile", "Details", "User", new { e_id="[email protected]"})
  • 它不會重定向我在用戶控制器詳細action.when我給這樣的URL:
    http://localhost:48096/User/[email protected]
    它工作正常。在此先感謝

    回答

    0

    使用一樣,如果你想傳遞的任何自定義HTML屬性鏈接元素此

    @Html.ActionLink("Profile", "Details", "User", new { e_id="Context.User.Identity.Name},null) 
    

    它使用此重載

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

    ,你可以替換的是第五個參數

    例:

    @Html.ActionLink("Profile", "Details", "User", new { e_id="yourvalue"},new {@class="myCSsClassName"}) 
    
    +0

    謝謝@Shyju,我應該如何得到我的routeValues,HtmlAttributes?請描述更多一點.... – 2012-04-28 09:54:05

    +0

    謝謝@Shyju,我的actionLink現在作爲:<

  • @ Html.ActionLink(「Profile」,「Details」,「User」,new {e_id = Context.User.Identity。 Name},null)
  • 2012-04-28 10:00:46

    +0

    @AwladLiton它修復了你的問題嗎? – Shyju 2012-04-28 15:18:01