I want to create a simple HtmlHelper.ActionLink
extension that will add a value to the route's value dictionary. The parameters will be identical to HtmlHelper.ActionLink
, HtmlHelper.ActionLink
.:
public static MvcHtmlString FooableActionLink( this HtmlHelper html, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes) {
The logic of what I add to routeValues
is somewhat verbose, so my desire is to put it in an extension method helper instead of repeating it in every view.
I have a solution that seems to work (posted as an answer below), but:
- For such a simple task it seems unnecessarily complicated.
- All castings amaze me as fragile, for example, there are some cases when I will throw a NullReferenceException or something like that.
Please post any suggestions for improvements or better solutions.
source share