Partial View is not loaded after main page is rendered

31 viewsajaxc++jqueryrazor pages
0

I have a razor main page with a selector that is loaded with the OnGet() event, when the user clicks in a value of this selector a jQuery function is called to load a partial view with some values.

Everything works fine here, but now I want to show the partial view with the values of the first value from the selector when the page is rendered.

In order to do that a create this jQuery function (which is exactly the same that I use for load the partial view when the user clicks on the selector):

<div id="partialView"></div>

$(document).ready(function (e) {
    //These are hidden inputs for obtain the values                                        
    var value1 = document.getElementById("value1").value;
    var value2 = document.getElementById("value2").value;

    var url = '/(CONTROLLER)/(ACTION)/' + value1 + '/' + @Model.Id + '/' + value2 + '/';

    $.ajax({
        type: "GET",
        url: url,
        success: function (data) {
            $('#partialview').html(data);
        }
    });
})

If I put a breakpoint in the controller I can see that the function is hit, but the partial view is not shown after it finished.

I think the problem could be related that the page hasn’t finished rendering when the jQuery function is being invoked but I’m not sure.