0

おそらくajaxの経験が浅いために、奇妙な問題と戦っています。何らかの理由で、ActionResult が PartialView を返す前に、Ajax 関数がエラー警告ダイアログを起動します。

私のajax関数がエラーをスローする理由、または私が間違っていることさえ、誰でも見つけることができますか?

私のJquery

function GetSalesLinesByArea(e) {
var areaId = treeView().getItemValue(e.item);
$('#HiddenAreaId').val(areaId);
var url = '/SalesLine/IndexPartial/';
$.ajax({
    type: "GET",
    dataType: "html",
    url: url,
    data: { areaNodeId: areaId },
    success: function (data) {
        $('#HuntingGrid').html(data);
        alert("success!");
    },
    error: function () {
        alert("error!");
    }
  });
}

私の見解 Index.cshtml

@using Telerik.Web.Mvc.UI
@using Veidivefur.Model.Entity
@model Veidivefur.ViewModels.SalesLineViewModel
@{
    ViewBag.Title = "Hlunnindi";
}

<div id="HuntingGrid">
    @{ Html.RenderPartial("IndexPartial"); }
</div>

私のパーシャルビュー IndexPartial.cshtml

@using Telerik.Web.Mvc.UI
@model Veidivefur.ViewModels.SalesLineViewModel

<div>
    @(Html.Telerik().Grid(Model.SalesLines)
        .Name("Grid")
        //More Telerik stuff
</div>

*コントローラーの私のインデックスActionResult *

    public ActionResult Index()
    {
        List<CombinedSalesLine> combinedSalesLines =
            GenerateSalesLines(_salesLineModel.FindAllSalesLinesLargerThanToday(0));

        return View(new SalesLineViewModel(combinedSalesLines));
    }

*コントローラーの私のIndexPartial ActionResult *

    public ActionResult IndexPartial(string areaNodeId)
    {
        int areaNodeInt = Convert.ToInt32(areaNodeId);

        List<SalesLine> saleslines = areaNodeInt == 0 ? _salesLineModel.FindAllSalesLinesLargerThanToday(0)
            : _salesLineModel.FindAllSalesLinesLargerThanToday(areaNodeInt);

        List<CombinedSalesLine> combinedSalesLines = GenerateSalesLines(saleslines);

        return PartialView("IndexPartial", new SalesLineViewModel(combinedSalesLines));
    }
4

1 に答える 1

0

問題を解決しました!私の質問で発行したコードは正しいようです。問題は、ajax 関数を呼び出す方法にありました。使用していた URL は別の関数も呼び出していたため、ajax 関数がエラーをスローしました。私は非常にばかげていると感じますが、それが解決されてうれしいです。

于 2012-10-16T19:46:33.483 に答える