Using Asp.net Core Kendo UI tooltip htmlhelper how do I pass a function for content

1 Answer 195 Views
ToolTip
Carlos
Top achievements
Rank 1
Carlos asked on 21 Jul 2021, 05:46 PM | edited on 21 Jul 2021, 05:48 PM

I can not figure out how I can pass a function for content in an Asp.net core to tooltip.  In the JQuery examples you can do something like this:

    $("#Name").kendoTooltip({
        content: function (e) {
            return $(e.target).data('tooltip');
        }
    })
I have been trying to pass a function to the htmlhelper and can not figure it out.  I have tried passing with events, and puting a function in the content.  I have no joy.
@(Html.Kendo().Tooltip()
    .For("#Name")
    .AutoHide(true)
    .Position(TooltipPosition.Top)
    .Content("TEST TEST")
    .Width(120)
    //.Events(events => events.ContentLoad("showTooltip"))
    )
Also can I use a class in the For, like .For(".form-tooltip")?
Carlos
Top achievements
Rank 1
commented on 22 Jul 2021, 10:08 AM

I figured it out. I change to the tag helper and used the content-handler property. I assume that is the same as the html helper.

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 26 Jul 2021, 02:07 PM

Hello Carlos,

In the Tooltip Html helper you can use a function as demonstrated below:

<span class="form-tooltip">Hover me</span>

@(Html.Kendo().Tooltip()
	.For(".form-tooltip")
	.ContentHandler("contentHandler")
	.Position(TooltipPosition.Top)
	.Width(200)
	.Height(100)
)

<script>
	function contentHandler(e) {
		var target = e.target; // the element for which the tooltip is shown
		return target.text();
	}
</script>

As for using a class in the .For() configuration, the answer is yes. The snippet shows this as well.

Regards,
Ivan Danchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Carlos
Top achievements
Rank 1
commented on 26 Jul 2021, 02:44 PM

Thank you for your answer. It solved my problem
Tags
ToolTip
Asked by
Carlos
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or