refreshing html.renderaction with ajax request

时间秒杀一切 提交于 2019-12-07 06:53:39

问题


I have div that renders image gallery on my page

        <div id="gallery">       
    @{
        Html.RenderAction("UserGallery");
     }

I have this function which runs on the completion of a successful upload of a new image

        function filesUploadOnSuccess(e) {
            function updateCart() {
                //var tdata = $(frm).serialize(); 
                // or your data in the format that will be used ??
                $.ajax({
                    type: "GET",
                    //data: tdata,
                    url : '@Url.Action("UserGallery")',
                    dataType: "json",
                    success: function (result) { success(result); }
                });
            };
        }

        function success(result) {
            $("#gallery").html(result);
        }

the problem is that the gallery div doesnt get updated.


回答1:


dateType should be "html", not "json", if your action returns a PartialViewResult:

public ActionResult UserGallery()
{
  // do something
  return PartialView();    
}

and

 $.ajax({
    url : '@Url.Action("UserGallery")',
    dataType: "html",
    success: function (result) { success(result); }
 });


来源:https://stackoverflow.com/questions/20110557/refreshing-html-renderaction-with-ajax-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!