MVC PartialView不刷新数据

use*_*678 2 c# asp.net-mvc renderpartial asp.net-mvc-partialview asp.net-mvc-4

我有一个索引页面:

@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>
Run Code Online (Sandbox Code Playgroud)

部分视图(_VentasTable):

@model AlfoncinaMVC.Models.VentaIndexViewModel

<table>
    <thead>

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

有了这个控制器:

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);
        }
Run Code Online (Sandbox Code Playgroud)

在调用Html.RenderPartial之后,我无法在局部视图(_VentasTable)中刷新数据(不在HTML.Partial中,请注意我的代码中有注释.)在我的部分放置断点之后view我看到数据从数据库查询中变为CHANGED,但是在部分视图中没有替换此数据.有什么帮助吗?

Igo*_*gor 7

正如@StephenMuecke所说 - "你需要将返回的数据添加到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);
  }
});
Run Code Online (Sandbox Code Playgroud)