任何人都可以找出为什么我的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>
* 我在Controller *中的索引ActionResult
public ActionResult Index()
{
List<CombinedSalesLine> combinedSalesLines =
GenerateSalesLines(_salesLineModel.FindAllSalesLinesLargerThanToday(0));
return View(new SalesLineViewModel(combinedSalesLines));
}
* 我在Controller *中的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));
}
答案 0 :(得分:0)
我解决了这个问题!我用我的问题发出的代码似乎是正确的。问题在于我调用我的ajax函数的方式,我使用的url也称为另一个函数,因此ajax函数引发了错误。我感到非常愚蠢,但很高兴它得到了解决。