【问题标题】:refreshing html.renderaction with ajax request使用 ajax 请求刷新 html.renderaction
【发布时间】:2013-11-21 01:12:47
【问题描述】:

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

问题是画廊 div 没有得到更新。

【问题讨论】:

    标签: jquery asp.net-mvc-4 renderaction


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2012-09-14
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 2018-02-09
      相关资源
      最近更新 更多