so here it is:
I have an html helper that displays an ActionLink with optional parameters for the current url in it. this html helper also allows you to add additional parameters as you wish and combines them into 1 RouteValueDictionary .
public static string ActionLinkwParams(this HtmlHelper helper, string linktext, string action, string controller, object extraRVs, object htmlAttributes) {
this works fine, but now I have added SecurityAware Actionlinks.
So
return helper.ActionLink(linktext, action, controller, m, htmlAtts).ToHtmlString();
becomes
return helper.SecurityTrimmedActionLink(linktext, action, controller, m, htmlAtts);
which then calls:
public static string SecurityTrimmedActionLink(this HtmlHelper htmlHelper, string linkText, string action, string controller, object extraRVs, object htmlAttributes) { return SecurityTrimmedActionLink(htmlHelper, linkText, action, controller, extraRVs, htmlAttributes, false); } public static string SecurityTrimmedActionLink(this HtmlHelper htmlHelper, string linkText, string action, string controller, object extraRVs, object htmlAttributes, bool showDisabled) { if (controller == null) { RouteData routeData = htmlHelper.ViewContext.RouteData; controller = routeData.GetRequiredString("controller"); } if (IsAccessibleToUser(action, controller)) { return htmlHelper.ActionLink(linkText, action, controller, extraRVs, htmlAttributes).ToHtmlString(); } else { return showDisabled ? String.Format("<span>{0}</span>", linkText) : ""; } }
Now it does NOT work. it compiles, but my url doesn't look very good.
<a count="3" keys="System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.Object]" values="System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.Object]" href="/2011-2012/Instelling?Count=3&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D">Back to List</a>
as you can see, what previously worked does not do it now, because it accepts RouteValueDictionary objects as objects, which does not give me the wrong result that I want.
so I thought, "What if I do them RouteValueDictionary .
if (IsAccessibleToUser(action, controller)) { RouteValueDictionary parsedextraRVs = null; if (extraRVs != null && extraRVs.GetType().Name == "RouteValueDictionary") { parsedextraRVs = (RouteValueDictionary)extraRVs; } RouteValueDictionary parsedHtmlAttributes = null; if (htmlAttributes != null && htmlAttributes.GetType().Name == "RouteValueDictionary") { parsedHtmlAttributes = (RouteValueDictionary)htmlAttributes; } return htmlHelper.ActionLink(linkText, action, controller, parsedextraRVs == null ? extraRVs : parsedextraRVs, parsedHtmlAttributes == null ? htmlAttributes : parsedHtmlAttributes).ToHtmlString(); }
but this also gives me the url that I just wrote above. Why does this work in my ActionLinkwParams method, but not when ActionLinkwParams calls the SecurityTrimmedActionLink method? and how to fix it?