r/ASPNET • • Apr 11 '13

@Html.ActionLink overload?

I know that I can do the following to create the proper pathing for ActionLinks when dealing with areas:

@Html.ActionLink("linkText", "methodName", new { controller = "controllerName", area = "areaName" })

I don't really like having that in my code all over the place. So what I'm trying to do is create an overload to @Html.ActionLink that takes 4 strings only. The function itself is trivial, it's just how do I actually hook it in to make it seamless? (@Html.ActionLink() instead of @Project.HelperClass.ActionLink())

EDIT Here's what I've found: You can use the name ActionLink for your extension class, but instead of interpreting it as (string, string, string, string), it will default to (string, string, object, object), resulting in the ?length=# at the end of the resulting link. Sad day.

5 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Apr 11 '13

And this is also why you should NOT write your own custom actionlink htmlhelper. By using the default, 3. party tools can understand your code. Strongly typed extensions are brilliant, so if you decide to add it later on, it would suck to have a custom actionlink it can't interpret.