Create a custom ActionLink

前端 未结 2 1271
天命终不由人
天命终不由人 2020-12-20 06:44

I want to create a custom actionlink but I don\'t know how to do this while fulfilling my needs. I worked with custom htmlhelpers before but this is a bit more tricky for me

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 07:08

    How about following code,

    @Html.ActionLink("Click here","Trip","Index", new { area= "Travel", tabmenu= "Index"}, new { @class = "font-color-blue" })
    

    EDIT

    You can use a extension method like this,

    public static MvcHtmlString CustomActionLink(this HtmlHelper htmlHelper, string linkText, string area, string controller, string tabMenu, string action, RouteValueDictionary routeValues, IDictionary htmlAttributes)
    {
        routeValues.Add("area", area);
        routeValues.Add("tabMenu", tabMenu);
        return htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes);
    }
    

提交回复
热议问题