我使用telerik和girdaction attribut为我的视图制作了一个网格。当我运行应用程序时,我无法访问该视图,并收到错误消息:
此请求已被阻止,因为在GET请求中使用此信息时,可能会向第三方网站披露敏感信息。要允许GET请求,请将JsonRequestBehavior设置为AllowGet。
我的控制器看起来像ActionResult" OrderDetailsReport"应该将网格中的订单对象列表返回到视图:
public class GAStatisticsController : Controller
{
[GridAction(EnableCustomBinding = true)]
public ActionResult GetOrderDetails(GridCommand command, GAStatisticsListModel model)
{
DateTime? startDateValue = (model.StartDate == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Date, _dateTimeHelper.CurrentTimeZone);
DateTime? endDateValue = (model.EndDate == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Date, _dateTimeHelper.CurrentTimeZone).AddDays(1);
OrderStatus? orderStatus = model.OrderStatusId > 0 ? (OrderStatus?)(model.OrderStatusId) : null;
PaymentStatus? paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)(model.PaymentStatusId) : null;
ShippingStatus? shippingStatus = model.ShippingStatusId > 0 ? (ShippingStatus?)(model.ShippingStatusId) : null;
var orders = _orderService.SearchOrderStatistics(startDateValue, endDateValue, orderStatus,
paymentStatus, shippingStatus, model.CustomerEmail, model.OrderGuid);
var resultOrders = orders.Where(o => o.PaymentStatus == PaymentStatus.Paid)
.GroupBy(g => g.CreatedOnUtc.Date.ToString("yyyyMMdd"))
.Select(s => new GCOrdersModel(s.Key, s.Count(), s.Sum(x => x.OrderProductVariants.Count()))).ToList();
List<GCOrdersModel> TotalOrdersPaid = new List<GCOrdersModel>();
foreach (var r in resultOrders)
{
TotalOrdersPaid.Add(r);
}
var Orders = TotalOrdersPaid;
var OrderModel = new GridModel<GCOrdersModel>
{
Data = Orders,
Total = Orders.Count
};
return new JsonResult
{
Data = OrderModel
};
}
}
视图看起来像这样(根据用户使用@Html.EditorFor dateTimePickers选择的StartDate和EndDate来加载数据。当点击提交时,应该加载数据,但我甚至无法访问查看所有atm):
@model GAStatisticsListModel
@using Nop.Admin.Models.GAStatistics;
@using Nop.Admin.Controllers;
@using Telerik.Web.Mvc.UI.Html;
@using System.Web.Mvc;
@using System.Linq;
@using Telerik.Web.Mvc.UI
@{
ViewBag.Title = "GetOrderDetails";
Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}
@using (Html.BeginForm(GCOrdersModel))
{
<h2>GetOrderDetails</h2>
<p>Hesan!</p>
<table class="adminContent">
<tr>
<td class="adminTitle">
@Html.NopLabelFor(model => model.StartDate):
</td>
<td class="adminData">
@Html.EditorFor(model => model.StartDate)
</td>
</tr>
<tr>
<td class="adminTitle">
@Html.NopLabelFor(model => model.EndDate):
</td>
<td class="adminData">
@Html.EditorFor(model => model.EndDate)
</td>
</tr>
<tr>
<td class="adminTitle">
@Html.NopLabelFor(model => model.GAStatisticsId ):
</td>
<td class="adminData">
@Html.DropDownList("GAStatisticsId", Model.AvailableGAStatistics)
<input type="button" id="GAStatisticsReport-Submit" class="t-button" value="@T("Admin.Common.Search")" />
</tr>
</table>
<table class="adminContent">
<tr>
<td>
@(Html.Telerik().Grid<GCOrdersModel>()
.Name("orderDetails-grid")
.Columns(columns =>
{
columns.Bound(x => x.Date);
columns.Bound(x => x.TotalOrders);
columns.Bound(x => x.TotalProducts)
}
)
.Groupable()
.Sortable()
.Pageable(settings => settings.PageSize(20).Position(GridPagerPosition.Both))
.DataBinding(dataBinding => dataBinding.Ajax().Select("GetOrderDetails", "GAStatistics"))
.ClientEvents(events => events.OnDataBinding("onDataBinding"))
)
</td>
</tr>
</table>
<script>
var first = true;
$(document).ready(function () {
if ($("select[name='GAStatisticsId'] option:selected").text() == "OrderStatistics")
onDataBinding()
$("#GAStatisticsReport-Submit").click(function () {
//search
var grid = $('#orderDetails-grid').data('tGrid');
grid.currentPage = 1; //new search. Set page size to 1
grid.ajaxRequest();
return false;
})
function onDataBinding(e) {
if (first) {
e.preventDefault();
first = false;
}
else {
var searchModel = {
StartDate: $('#@Html.FieldIdFor(model => model.StartDate)').val(),
EndDate: $('#@Html.FieldIdFor(model => model.EndDate)').val()
};
e.data = searchModel;
}
}
});
</script>
}
Anny想法为什么我无法访问视图?我必须把&#34; JsonRequestBehavior.AllowGet&#34;代码中的某个地方?
答案 0 :(得分:0)
您目前正在返回JsonResult
。要返回ViewResult
,请使用类似
return View(model);
或
return View("ViewName", model);