This is a migrated thread and some comments may be shown as answers.

Click on a Badge to invoke controller

2 Answers 22 Views
Badge
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Veteran
Anders asked on 22 Feb 2021, 07:58 AM

Hi,

I am trying to create logic to allow clicking in the Badge, based on the recommendations in https://www.telerik.com/forums/badge-click-to-execute-code-in-controller-class, to run code in the Controller but needs some direction. 

The Controller is called (using ajax call in example 1) when clicking on "Get total" (in example 2) but what to use in the badge to make it execute? Not the name of it, right? (already tried this and nothing happens...)

 

Please describe on how to invoke the ajax call from a badge or tell me if badges cannot  be used in this way. I would also like to know the rationale in not embedding native click logic to the badge. I mean, if showing an aggregated value of something, why wouldn't you want to link to the data the value is calculated from?

 

 

 

 

 

 

Example 1

<script>
    $("#badge-total").click(function () {
        $.ajax({
        url: '@Url.Action("ShowTotalGrid")', 
        dataType: "json", 
        type: "POST", 
        contentType: 'application/json; charset=utf-8', 
        cache: false, 
        data: {}, 
        success: function (data) {           
            if (data.success) {
                alert(data.message);
            }
        },
        error: function (xhr) {
            alert('error');
        }
    });
});
</script>

 

 

Example 2

<div id="badge-total">
    Get total
</div>

 

/Regards Anders

2 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 23 Feb 2021, 05:50 PM

Hi Anders,

I have already followed up with a response to the forum thread that you provided. Could you confirm that the solution provided is sufficient for your scenario? Or, if I should come up with an alternative? 

Also, it is recommended to avoid submitting duplicate threads as this might pollute your history, and navigating between past threads of yours would be more difficult.

 

Regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Anders
Top achievements
Rank 1
Veteran
answered on 24 Feb 2021, 07:28 AM

Hi Tsvetomir,

It is confirmed. Thanks.

Regards Anders

Tags
Badge
Asked by
Anders
Top achievements
Rank 1
Veteran
Answers by
Tsvetomir
Telerik team
Anders
Top achievements
Rank 1
Veteran
Share this question
or