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 ?
yosr jemili4 pointsPosted Aug 7, 2015, 9:41 AM EDT
I edited the code but I don't know if its a good idea.
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)); } }