Tooltip in ASP.NET MVC Rating Control

25 Jan 20233 minutes to read

The ASP.NET MVC rating control supports tooltip to show additional information in rating items by setting the ShowTooltip property. If enabled, the tooltip appears when the user hovers over a rating item.

@using Syncfusion.EJ2.Inputs

@Html.EJS().Rating("rating").Value(3).ShowTooltip(true).Render()
public ActionResult ShowTooltip()
{
    return View();
}

ASP.NET MVC Rating Control with Tooltip

Tooltip template

You can use the TooltipTemplate tag directive to specify a custom template for the Tooltip of the rating. The current value of the rating will be passed as the value property in the template context when building the content of the tooltip. This allows you to include dynamic information about the rating in the template.

@using Syncfusion.EJ2.Inputs

@Html.EJS().Rating("rating").Value(4).TooltipTemplate("#template").Render()

<script id="template" type="text/x-jsrender">
    ${if(value==1)}
    <b>Angry</b>${else if(value==2)}
    <b>Sad</b>${else if(value==3)}
    <b>Neutral</b>${else if(value==4)}
    <b>Good</b>${else}
    <b>Happy</b>
    ${/if}
</script>
public ActionResult TooltipTemplate()
{
    return View();
}

ASP.NET MVC Rating Control with Tooltip Template

Tooltip customization

You can customize the appearance of the tooltips using the CssClass property of the ASP.NET MVC Rating control and by defining the custom styles for tooltip elements like the below example.

NOTE

You can find more information about customizing the appearance of the tooltip in the Tooltip Customization documentation.

@using Syncfusion.EJ2.Inputs

@Html.EJS().Rating("rating").Value(3).CssClass("customtooltip").Render()

<style>

    /* To change the radius of the tooltip corners. */
    .customtooltip.e-tooltip-wrap {
        border-radius: 3px;
    }

    /* To change the size of the tooltip content. */
    .customtooltip.e-tooltip-wrap .e-tip-content {
        font-size:14px;
    }

    /* To change the border color and width for tooltip. */
    .customtooltip.e-tooltip-wrap.e-popup {
        border: 2px solid #969393;
    }

    /* To change the color for arrow of the tooltip. */
    .customtooltip.e-tooltip-wrap .e-arrow-tip-inner.e-tip-bottom {
        border: 12px solid #9693
    }

    /* To change the top border color for arrow of the tooltip. */
    .customtooltip.e-tooltip-wrap .e-arrow-tip-outer.e-tip-bottom {
        border-top: 12.5px solid #969393;
    }

</style>
public ActionResult CustomTooltip()
{
    return View();
}

ASP.NET MVC Rating Control with Tooltip Customization