gpt4 book ai didi

javascript - jsonresult 错误结果

转载 作者:行者123 更新时间:2023-12-02 19:36:43 29 4
gpt4 key购买 nike

我在 Controller 中使用以下操作,并且尝试在 jq.grid 中显示房间数量;

  public JsonResult Incercare() 
{
DBContext.Current.Open();
var data = new
{
Title="Total",
Rezervari = Reservation.SelectByReservationDate(5).FirstOrDefault().NumarRezervari
};
var result = new JsonResult(){Data = data,JsonRequestBehavior =JsonRequestBehavior.AllowGet};
return result;
}

这是我的观点:

    @model LicentaTest.Models.Reservation

@{
ViewBag.Title = "Incercare";
}

<script type="text/javascript">
$(function () {
var requestUrl = '@Url.Action("Incercare","Grafice")';

$("#cartResults").jqGrid({

url: requestUrl,
datatype:'json',
mtype: 'GET',
emptyrecords: "No results",
colNames: ['Title','Rezervari'],
colModel: [
{ name: "Title", width: 350, editable: false, searchoptions: {}, index: "Title" },
{ name: "Rezervari", width: 100, editable: false, searchoptions: {}, index: "Rezervari"}
],
pager: $('#cartPager'),
rowList: [], // disable page size dropdown
pgbuttons: false, // disable page control like next, back button
viewrecords: false, // disable current view record text like 'View 1-10 of 100'
sortname: 'id',
sortorder: 'asc',
loadonce: false,
sortable: true,
scrollrows: true,
height: 300,
pgtext: null,
hoverrows: false,
footerrow: true,
userDataOnFooter: true,
emptyDataText: "Your Cart is Empty"

});
});
</script>
<div class="styler">
<fieldset class="ui-widget">
<legend class="ui-state-legend-default ui-corner-top ui-corner-bottom">Review Your Cart </legend>
<div id="update-message-disp" class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;width: 500px">
<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"> </span><strong>Cart modified</strong><br />
</p>
</div>
<br />
<table id="cartResults">
</table>
<div id="cartPager">
</div>
</fieldset>
</div>

但不是得到这样的东西: enter image description here

我明白了:

enter image description here

我做错了什么?

最佳答案

这是因为在您的 Controller 中您返回一个 JsonResult ,它将 json 对象渲染到 View 。
相反,您应该返回 ViewResultPartialViewResult 并确保将对象作为参数传递给它。

关于javascript - jsonresult 错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10852257/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com