使用ajax请求刷新html.renderaction



我有一个在页面上渲染图像库的div

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

我有这个功能,它在成功上传新图像后运行

        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);
        }

问题是gallerydiv没有得到更新。

dateType应该是"html",而不是"json",如果您的操作返回PartialViewResult:

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

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

最新更新