关于这个主题的其他帖子对我有所帮助,但并不完全。我正在从 Wcf 服务(包含在我的 MVC 4 项目中)检索数据,如下所示:
仓库控制器.cs
WarehouseInput objWI = new WarehouseInput();
public ActionResult Index(WarehouseInput value)
{
objWI.count = 15;
objWI.offset = 0;
objWI.query = "";
objWI.sort = "ID";
objWI.order = "asc";
objWI.ID = 0;
objWI.RowID = 0;
Service1 c = new Service1();
c.GetWarehouseList(objWI);
//var model = c.GetServices();
update 1 -----> return View(objWI);
//return GetWarehouseList(objWI);
update 2 -----> //return Json(objWI, JsonRequestBehavior.AllowGet);
}
我在我的 Json 对象中获取数据......
Index.cshtml 编辑:
@model MvcApplication1.WS.DataContracts.WarehouseInput
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<script type="text/javascript">
alert('0');
$.ajax({
url: '@Url.Action("Index")',
type: 'GET',
cache: false,
success: function(resp) {
alert(resp);
if (resp.WarehouseResults != null) {
var objTemp = resp.WarehouseResults;
//var from = resp.offset, to = from + resp.WarehouseResults.length;
//data.length = parseInt(resp.total);
//for (var i = 0; i < resp.WarehouseResults.length; i++) {
// data[from + i] = resp.WarehouseResults[i];
// data[from + i].index = from + i;
//}
//$("#lblRows").html("<b>Total: " + resp.total + "</b>");
//onDataLoaded.notify({ from: from, to: to });
}
else {
//i = indicators.pop();
//if (i != null)
// i.fadeOut();
alert('Error loading the page');
}
alert('1');
}
});
alert('1.5');
var values = @Html.Raw(Json.Encode(Model.WarehouseResults));
var data = [];
var grid;
var validator;
问题是控件永远不会转到cshtml。如何将 json 对象传递给视图(UI)?如何在我使用的 slickgrid 中显示它?编辑:需要修改 javascript 代码,但首先我必须让控件到达那里。