我正在解决一个奇怪的问题,这可能是由于我对 ajax 缺乏经验。出于某种原因,我的 Ajax 函数甚至在我的 ActionResult 返回 PartialView 之前就触发了我的错误警报对话框。
任何人都可以发现为什么我的 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));
}