0

我有一个控制器,我得到结果 exampleController.cs:

public expChart{
...
   public ActionResult ByContainer(int id)
    {
        var elementIds = _systemSettings.Z3FromZBIds; // CritialWorkPermitIds; 

        var kpiElements = CacheService.AllVisibleElements
                                      .Where(x => elementIds.Contains(x.Id)).ToList();

        var container = _kpiContainerService.Find(id);

        var result = _kpiTrendService.MonthByContainer(kpiElements, container);
        return AsJson(result);
    } 
} 

我在 example.cshtml 中调用它:

<div class="panel" style="display: none;" id="bottom-area-trend-charts" ng-ontroller="exampleController">
    <div >
        TEST
        {{element.Name}}
    </div>

</div>

我认为这是我的召唤有问题。如何在我的控制器中调用结果?

提前致谢

4

1 回答 1

0

使用这样的东西:

<script type="text/javascript">
    $(function () {
        $.ajax({
            url: "/YourController/ByContainer",
            type: "GET",
            dataType: 'html',
            data: { id: 10 }, // the value id for call your controller
            success: function (data) {
                // make sure your result variable is enumerable.
                $(data).each(function (index, element) {
                    $("#bottom-area-trend-charts div").append("<p>" + element.Name + "</p>");
                });
            },
            error: function (xqr, errorMessage) {
                alert(errorMessage);
            }
        });
    });
</script>

并将您的操作更改为:

public JsonResult ByContainer(int id)
{
    var elementIds = _systemSettings.Z3FromZBIds; // CritialWorkPermitIds; 

    var kpiElements = CacheService.AllVisibleElements
                                    .Where(x => elementIds.Contains(x.Id)).ToList();

    var container = _kpiContainerService.Find(id);

    var result = _kpiTrendService.MonthByContainer(kpiElements, container);

    return Json(result, JsonRequestBehavior.AllowGet);
} 
于 2013-06-24T13:05:36.830 回答