Skip to content

Capture data after click on custom helper hyperlink

yosr jemili

Asked Aug 7, 2015, 7:18 AM EDT1 answer
Share
LinkedInX

Hello

As Initiation I have to create a custom helper for hyperlink like in the code above :

C#
 class CapturedLink { public static MvcHtmlString Hyperlink(this HtmlHelper helper, string url, string linkText) { return MvcHtmlString.Create(String.Format("<a href='{0}'>{1}</a>", url, linkText)); } }

but what i am missing is that I want to capture some data (application name,page ...etc ) when I click on that link

How we can do this ?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    I edited the code but I don't know if its a good idea.

    C#
     class CapturedLink { public static MvcHtmlString Hyperlink(this HtmlHelper helper, string url, string linkText, object innerHtml, object htmlAttributes = null, object dataAttributes = null) { //return MvcHtmlString.Create(String.Format("<a href='{0}'>{1}</a>", url, linkText)); var link = new TagBuilder("a");             link.MergeAttribute("href", url);             link.InnerHtml = innerHtml.ToString();             link.MergeAttributes(new RouteValueDictionary(htmlAttributes), true); if (dataAttributes != null) { var values = new RouteValueDictionary(dataAttributes); foreach (var value in values) {                     link.MergeAttribute("data-" + value.Key, value.Value.ToString()); } } return MvcHtmlString.Create(link.ToString(TagRenderMode.Normal)); } }
    0