How can I make up a RouteLink in a custom HtmlHelper? I know how to make it in a partial view but I want to build up a new link in a custom htmlhelper extension method with the use of a RouteLink. How to accomplish this?
Update: I noticed HtmlHelper.GenerateRouteLink. But what do I need to put in as parameters?
Here's an example. Let's suppose that you want to wrap the links into a
div
tag with some given class so that your resulting html looks like this:You could write the following extension method:
which could be used like this:
and this will produce the desired markup. Any other overloads of
RouteLink
could be used if necessary.