Having issues with ASP.NET MVC AJAX PartialView not loading Telerik UI components

I am facing an issue with a PartialView that I update using AJAX. The HTML elements load correctly when updating the Div with AJAX, but the Telerik chart is not loading. The datasource in the chart does not call the Action method:

.DataSource(ds => ds.Read(read => read.Action("Movies_Read", "Movies")))

When the PartialView is initially loaded without AJAX, the datasource calls the action method and the chart loads correctly.

As per the guidance from Telerik ASP.NET PartialView AJAX, there needs to be a JavaScript call for the OnSuccess event:

<script type="text/javascript">
  function updatePlaceholder(context) {
    // the HTML output of the partial view
    var html = context.get_data();

    // the DOM element representing the placeholder
    var placeholder = context.get_updateTarget();

    // use jQuery to update the placeholder. It will execute any JavaScript statements
    $(placeholder).html(html);

    // return false to prevent the automatic update of the placeholder
    return false;
}

I have tried implementing the provided JavaScript, but the get_data() and get_updateTarget() functions do not exist even though I have included MicrosoftAjax.js and MicrosoftMvcAjax.js. These may be deprecated. I have also attempted other JavaScript functions without success.

My AJAX call is as follows:

@using (Ajax.BeginForm("UpdateMoviesChart", "Movies", new AjaxOptions { UpdateTargetId = "MoviesDiv", InsertionMode = InsertionMode.Replace, OnSuccess = "updatePlaceholder", }))

How can I ensure that the Telerik Chart loads correctly when using AJAX?

Answer №1

To enhance the view, it is important to include the following script for updating the Div element using Ajax:

View:

<div class="graph-container"></div>
<script>
    $(function () {
        $.ajax({
            url: "@(Url.Action("Graph_Read", "Graph"))",
            success: function (data) {
                $(".graph-container").html(data);
            }
        });
    })
</script>

Additionally, ensure that the controller is updated to return an ActionResult.

Controller:

public ActionResult UpdateGraph()
{
    return PartialView("update_graph_partial_view");
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging custom properties in HTML elements with JavaScript

I am in the process of creating a straightforward battleships game that utilizes a 10x10 table as the playing grid. My goal is to make it easy to adjust the boat length and number of boats, which is why I'm attempting to store data within the HTML obj ...

Converting an array to a JSON object using JavaScript

I need help with converting the following array into a JSON object: var input = [ 'animal/mammal/dog', 'animal/mammal/cat/tiger', 'animal/mammal/cat/lion', 'animal/mammal/elephant', 'animal/ ...

Sling file moving with an Ajax request

Currently, I am using an ajax call to delete files in the sling repository. Next, I need to figure out how to move files from 'copyFromURL' to 'moveToURL' utilizing the same method. $.ajax( { url : del_url, ...

Achieving enlightenment with Satori in NextJS: Transforming SVG to PNG in a NodeJS Environment

I am currently exploring the capabilities of satori and integrating it into my next.js api routes. (I'm unable to utilize the vercel/og package). While I have successfully set everything up, I'm facing a challenge in converting the svg image gen ...

The website that is not functioning properly due to Java/GWT being used behind an Apache reverse server

Seeking assistance with a website setup issue. The website, known as “www.mydomain.com” on the internet, is inaccessible due to being behind a BlueCoat reverse proxy and internally named as www.mydomain-internal.local. I aim to migrate the site behind ...

Execute the knockout function using jQuery

There's a scenario where I am trying to trigger a knockout method using jQuery. The Knockout viewModel has already been bound, but I'm unsure of how to call it using jQuery. Below is the snippet of my code: $(document).ready() { form_submit( ...

Retrieve data from a specific JSON array

Here is an example JSON data: { "results":{ "first":[ true, "Matthew" ], "second":[ false, "Unapplied" ], "third":[ fa ...

The button event is currently only targeting the initial class. (Jquery)

I am having an issue where only the first instance of the saveBtn class is being saved into local storage when clicked. Can anyone provide some assistance with this? Here is the HTML: <div class="hour-container" id="8am"> & ...

Automatically selecting the map center while using the Drawing Manager feature for placing markers

My application utilizes the Google Drawing Library. When a user clicks on the Add New Marker Button, the Drawing Manager is activated allowing the user to generate a marker by clicking anywhere on the map. Subsequently, the following listener is executed: ...

Creating a Select component in React without relying on the Material-UI library involves customizing a dropdown

Is there a way to achieve a material UI style Select component without using the material UI library in my project? I'm interested in moving the label to the top left corner when the Select is focused. export default function App({...props}) { retu ...

Trouble with Angular toggle switch in replicated form groups

Currently, I have a form group that contains multiple form controls, including a toggle switch. This switch is responsible for toggling a boolean value in the model between true and false. Depending on this value, an *ngIf statement determines whether cert ...

Having trouble getting the group hover animation to function properly in Tailwind CSS

Just starting out with tailwind css and running into a little issue. The hover animation I'm trying to apply isn't working as expected in this case. Instead of seeing the desired animated background when hovering over the group, it seems the back ...

applying the "active" class to both the parent and child elements

Looking for a way to apply an active class to both the parent and child elements when a user clicks on the child element within a list. The HTML structure is as shown below:- <ul class="tabs"> <li class="accordion"><a href="#tab1"> ...

Which comes first in AngularJS: ng-include or ng-repeat?

What is the outcome if I have a template containing ng-repeat and include it using ng-include? Will the included template have the completed ng-repeat, or will it be included without the ng-repeat being complete (and then completed after inclusion)? ...

Preventing Click Events from Firing During Drag in JavaScript

I have implemented a code for dragging containers left or right, which is functioning properly. Users can also click on the "thumb". However, I am facing an issue where a click event occurs even after dragging. I want to ensure that only either drag or cli ...

if a condition is not being properly assessed

Currently, I am working on a $.ajax call to retrieve data in JSON format. Within this JSON data, there is an element called "status." My code snippet checks if the value of `data.status` is equal to "success" and performs some actions accordingly. Despite ...

Having issues with clicking on a row in the table while using AJAX functionality

Experiencing a puzzling issue while attempting to add click functionality to table rows with AJAX, here is the JavaScript code used: //for tabs $(document).ready(function () { $("#tabs").tabs(); }); $(window).load(function() { jsf.ajax.addOnEven ...

Trouble with Displaying 3rd Level JQuery Dropdown Menu

Currently working on implementing a 3 level dropdown feature. I have been using a third-party responsive menu in Opencart and it's been working well. You can see a demo of it here: Unfortunately, Opencart does not natively support 3 level categories, ...

The destroySlider() function of BxSlider fails to work due to either an undefined slider or a function that is not

I'm facing an issue with my carousel setup using bxslider. Here is the code snippet responsible for initializing the carousel: jQuery(document).ready(function() { var carouselWidth = 640; var carousel; var carousel_Config = { minSlides: 1, ...

Navigating through a series of items in VueJS can be easily accomplished by using a

Below is the Vue instance I have created: new Vue({ el: '#app', data: { showPerson: true, persons: [ {id: 1, name: 'Alice'}, {id: 2, name: 'Barbara'}, {id: 3, name: &a ...