Friday, 26 October 2012

After getting the Ajax result from the Action Method the the view is not updating in mvc3/mvc4

One of my friend while doing a task of a project , he implemented the Ajax call to send request to the  action method. he had done it and resend the model to the client side, but the data is not updating in the view.

So, I thought of a while and scrutinized it and found that the model is updated when the data comes from the action method but it is not updating the view. so, here is the trick how to do it.

$.ajax({
                data: { retailLocation: $("#ddlLanguages").val().split('-')[1] + "-" + this.value },
                url: '/App/index',
                success: function (result) {
                    $("#container").empty().html(result);
                    $('#container').fadeIn('fast');


                },
                complete: function (result) {
                    $("#RetailPartnerLocation option:contains(" + currentselection + ")").attr('selected', 'selected');
                },
                Error: function (result) { alter("Error occured while processing"); }
            });


Here you need to empty the container where the previous data exist and bind the new data to it.

No comments:

Post a Comment