Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It turns out that an instance method will always be preferred over an extension method with the same signature. </p> <p>I was able to load a CustomHtmlHelper and put instance method ActionLink methods in the new class:</p> <pre><code>public abstract class CustomWebViewPage&lt;T&gt; : WebViewPage&lt;T&gt; { public new CustomHtmlHelper&lt;T&gt; Html { get; set; } public override void InitHelpers() { Ajax = new AjaxHelper&lt;T&gt;(ViewContext, this); Url = new UrlHelper(ViewContext.RequestContext); //Load Custom Html Helper instead of Default Html = new CustomHtmlHelper&lt;T&gt;(ViewContext, this); } } </code></pre> <p>And the HtmlHelper is as follows (ActionLink methods copied from Reflector without the LinkText error check:</p> <pre><code>public class CustomHtmlHelper&lt;T&gt; : HtmlHelper&lt;T&gt; { public CustomHtmlHelper(ViewContext viewContext, IViewDataContainer viewDataContainer) : base(viewContext, viewDataContainer) { } //Instance methods will always be called instead of extension methods when both exist with the same signature... public MvcHtmlString ActionLink(string linkText, string actionName) { return ActionLink(linkText, actionName, null, new RouteValueDictionary(), new RouteValueDictionary()); } public MvcHtmlString ActionLink(string linkText, string actionName, object routeValues) { return ActionLink(linkText, actionName, null, new RouteValueDictionary(routeValues), new RouteValueDictionary()); } public MvcHtmlString ActionLink(string linkText, string actionName, string controllerName) { return ActionLink(linkText, actionName, controllerName, new RouteValueDictionary(), new RouteValueDictionary()); } public MvcHtmlString ActionLink(string linkText, string actionName, RouteValueDictionary routeValues) { return ActionLink(linkText, actionName, null, routeValues, new RouteValueDictionary()); } public MvcHtmlString ActionLink(string linkText, string actionName, object routeValues, object htmlAttributes) { return ActionLink(linkText, actionName, null, new RouteValueDictionary(routeValues), AnonymousObjectToHtmlAttributes(htmlAttributes)); } public MvcHtmlString ActionLink(string linkText, string actionName, RouteValueDictionary routeValues, IDictionary&lt;string, object&gt; htmlAttributes) { return ActionLink(linkText, actionName, null, routeValues, htmlAttributes); } public MvcHtmlString ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes) { return ActionLink(linkText, actionName, controllerName, new RouteValueDictionary(routeValues), AnonymousObjectToHtmlAttributes(htmlAttributes)); } public MvcHtmlString ActionLink(string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary&lt;string, object&gt; htmlAttributes) { return MvcHtmlString.Create(GenerateLink(ViewContext.RequestContext, RouteCollection, linkText, null, actionName, controllerName, routeValues, htmlAttributes)); } public MvcHtmlString ActionLink(string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes) { return ActionLink(linkText, actionName, controllerName, protocol, hostName, fragment, new RouteValueDictionary(routeValues), AnonymousObjectToHtmlAttributes(htmlAttributes)); } public MvcHtmlString ActionLink(string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary&lt;string, object&gt; htmlAttributes) { return MvcHtmlString.Create(GenerateLink(ViewContext.RequestContext, RouteCollection, linkText, null, actionName, controllerName, protocol, hostName, fragment, routeValues, htmlAttributes)); } } </code></pre> <p>And finally, setting the pageBaseType int the <code>Views/Web.config</code> file to use the new custom WebViewPage:</p> <pre><code> &lt;system.web.webPages.razor&gt; ... &lt;pages pageBaseType="Fully.Qualified.Namespace.CustomWebViewPage"&gt; ... &lt;/pages&gt; &lt;/system.web.webPages.razor&gt; </code></pre> <p>Hope this helps someone else.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload