2012-04-28 87 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

    相关问题