MVC PartialView 不刷新数据

MVC PartialView is not refreshing data

我有一个索引页:

@model AlfoncinaMVC.Models.VentaIndexViewModel

@{
    ViewBag.Title = "Ventas";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script>
    var d = 1;
    setInterval(function () {
        d++;
        $('#testLabe').text(d);
        $.ajax("Ventas");
    }, 1000 * 1 * 1);
</script>

<div id="ventasTable">
    @{ Html.RenderPartial("_VentasTable"); }
    @*@Html.Partial("_VentasTable")*@
</div>

<label id="testLabe"></label>

使用局部视图 (_VentasTable):

@model AlfoncinaMVC.Models.VentaIndexViewModel

<table>
    <thead>

    </thead>
    <tbody>
        @foreach (var item in @Model.Ventas)
        {
            <tr>
                <td>
                    @item.nombreArticulo
                </td>
            </tr>
        }
    </tbody>
</table>

使用此控制器:

public ActionResult Ventas()
        {
            var db = new AlfonsinaEntities();
            var ventas = db.Set<Venta>();

            var vm = new VentaIndexViewModel
            {
                Ventas = ventas.Select(x => new VentaViewModel
                {
                    nombreArticulo = x.NombreArticulo
                }).ToList()
            };

            if (Request.IsAjaxRequest())
            {
                return PartialView("_VentasTable", vm);
            }
            return View("Ventas", vm);
        }

并且在调用 Html.RenderPartial 之后,我无法在局部视图 (_VentasTable) 中刷新数据,(HTML.Partial 也无法刷新,请注意我的代码中已注释.) 在我的局部视图上设置断点后,我看到数据已从数据库查询中更改,但该数据未在局部视图中被替换。有什么帮助吗?

正如@StephenMuecke 所说 - "You need to add the returned data to the DOM":

$.ajax({
  type: "GET",
  url: '@Url.Action("Ventas", "ControllerName")',
  async: true,
  cache: false,
  dataType: "html",
  success: function (data, textStatus, jqXHR) {
    $("#ventasTable").html(data);
  },
  error: function (jqXHR, textStatus, errorThrown) {
    alert(textStatus + " - " + errorThrown);
  }
});