Is it possible to write an extension method of the ASP.NET method Html.ActionLink ()?

I am currently trying to get around IE6 / 7 error, which requires wrapping the closing tag </a>with this IE-specific comment, to make some sort of dropdown menu:

<!--[if IE 7]><!--></a><!--<![endif]-->

Unfortunately, I cannot insert this directly into my page code like this:

<%= Html.ActionLink("LinkName<!--[if IE 7]><!--></a><!--<![endif]-->","Action","Controller") %>

How Html.ActionLink will do the safe thing and filter out the comment to prevent a Javascript injection attack. Okay, cool. I'm fine with that. Good design decision.

What I would like to do is write an extension method for this, but this process eludes me since I have not done this before.

I thought this would work, but Intellisense doesn't seem to pick up this extension method that I wrote.

public static class MyLinkExtensions
{
    public static string ActionLinkIE(this HtmlHelper htmlHelper,  
        string linkText, string actionName, string controllerName)
    {
        return LinkExtensions.ActionLink(htmlHelper, linkText, actionName, controllerName).
            Replace(@"</a>", @"<!--[if IE 7]><!--></a><!--<![endif]-->");
    }
}

Any suggestions?

: ? ( MyLinkExtensions)

, mousing <%= Html.ActionLink() %>, . ?

+3
2

, Extensions web.config:

<pages>      
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Linq" />
        <add namespace="Pretzel.Extensions.Html" />
      </namespaces>
</pages>

Intellisense.

+6

phil haack http://haacked.com/archive/2010/04/06/using-antixss-as-the-default-encoder-for-asp-net.aspx

ANtiXss http://wpl.codeplex.com/. Microsoft, :

  • JavascriptEncoding

, ajax javascript, JavascriptEncoding, , .

, , .

, Html:-(. , MVC3. , AnTiXss .

0

Source: https://habr.com/ru/post/1750351/


All Articles