[RESOLVED]Loading PartilaView with Ajax

i have some functionality to display the some list data and i had collapsable buttons before the list of data when loading the page.

for every list of data there is a option for request demo and if i click on request demo the form will be loaded .

for this i had just created a partial view and i am trying to call by using ajax 

 $(".Request").click(function () {
                alert("hai");
                $.ajax({
                    url: "/Services/Request",
                    contentType: "application/html;charset=utf-8",
                    type: "GET",
                    dataType:'html',
                    cache: false,
                    
                    success: function (data) {
                        $("#RequestInfo").html(data);
                    },
                    error: function (xhr)
                    { alert(xhr);}
                });
            });

but after this the entire form is again reloading and once again the collapsable buttons are inserted before that list.

how many times i just call this partial view then all the times the collapsable buttons are created so how to prevent with our form 

reloading to load the partila view

Hi,

Try to clear the content from #Requestinfo before loading new content.

 $(".Request").click(function () {
                alert("hai");
                $.ajax({
                    url: "/Services/Request",
                    contentType: "application/html;charset=utf-8",
                    type: "GET",
                    dataType:'html',
                    cache: false,
                    
                    success: function (data) {
$("#RequestInfo").html(""); $("#RequestInfo").html(data); }, error: function (xhr) { alert(xhr);} }); });

Hi Siva_540,

Thanks for your post.

I agree with  sen338,You should clear the content from #Requestinfo before loading new content.

There are some references:

H#ow to Load Partial Views in ASP.Net MVC Using jQuery Ajax

http://www.c-sharpcorner.com/UploadFile/d551d3/how-to-load-partial-views-in-Asp-Net-mvc-using-jquery-ajax/

#Rendering a Partial View and JSON Data Using AJAX in ASP.Net MVC

http://www.c-sharpcorner.com/UploadFile/3d39b4/rendering-a-partial-view-and-json-data-using-ajax-in-Asp-Net/

Hope this can be helpful.

Best Regards,

Eileen

Actually the problem is solved after changing the return type of the Action

public ActionResult Request()
{
return View("_Request");
}

To

public ActionResult Requst()
{
return PartialView("_Request");
}

Leave a Reply