Skip to content Skip to sidebar Skip to footer

Partial View Not Working Propely In Index View.

I am developing MVC application and using razor syntax. In this application I am giving comment facility. I have added a partial view, which loads the comment/Records from DB. In b

Solution 1:

To expand on what Alberto León is saying, the partial page load will not cause the document ready event to fire, so the re-rendered elements will not have the javascript event handlers registered after the first comment is added.

To resolve this, you could put the event registration code into a function, and call this both from the document ready event and the success handler of the AJAX call. Something like this:

functionAssignEventHandlers() {

    $('a.addremark').click(function () {
        ....
    });

    $("a.pagenumber").click(function () {
        var page = 0;
        page = parseInt($(this).attr("id"));

        $.ajax({
            url: '@Url.Action("GetPagedCustomers")',
            data: { "page": page },
            success: function (data) { 
                $("#customerlist").html(data);
                AssignEventHandlers();
            }
        });
        returnfalse;
    });
}

$(document).ready(function () {

    $('.RemarkBox').hide();

    AssignEventHandlers();
}

Solution 2:

In success function you need to recall the javascript, or the jquery code that makes the button work. Is an error that taked me a lot of time. Anything uploaded by ajax or any renderpartiAl needs to recall javascript.

$('.RemarkBox').load(url, function() {
  //RECALL JAVASCRIPT

});

Post a Comment for "Partial View Not Working Propely In Index View."