Kendo ui Grid显示json而不是网格Asp .net剃须刀 [英] Kendo ui Grid shows json instead of grid Asp .net razor

查看:90
本文介绍了Kendo ui Grid显示json而不是网格Asp .net剃须刀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图初始化Kendo ui网格.我可以使用View对象填充它, 但是当我尝试以Json格式执行此操作时(即,移至下一页时),我得到的屏幕显示的是json结果而不是我的视图.

I trying to initialize my Kendo ui grid. I am able to populate it using the View object, but when I try doing it in Json format (i.e. when moving to next page) I get a screen showing json results instead of my view.

这是控制器代码:

 public class CampaignsController : Controller
    {
        //
        // GET: /Campaigns/


        [HttpGet]
        public ActionResult Index()
        {
            return View(GetAllCampaigns());
        }


        public ActionResult Campaigns_Read([DataSourceRequest] DataSourceRequest request)
        {
           DataSourceResult result = GetAllCampaigns().ToDataSourceResult(request);
           return Json(result, JsonRequestBehavior.AllowGet);        
        }


        private static IEnumerable<NH_Campaign> GetAllCampaigns()
        {
            List<NH_Campaign> result = null;
            if (MBPDataAccess.Instance.GetAll(out result))
            {
                return result;
            }
            return new List<NH_Campaign>();
        }

,cshtml是:

@model IEnumerable<MBP.NH_Campaign>

<h2>View1</h2>


@(Html.Kendo().Grid(Model)
      .Name("CGrid")
      .Columns(columns =>
          {
              columns.Bound(p => p.CampaignID).Title("Id");
              columns.Bound(p => p.CampaignName).Title("Name");
              columns.Bound(p => p.ClickUrlC2C_OFF).Title("Click URL");
              columns.Bound(p => p.PlatformID).Title("Platform ID");
          })
      //.Groupable()
      .Pageable()
      //.Sortable()
      //.Filterable()
      .DataSource(dataSource => dataSource.Ajax().PageSize(2).Read(read => read.Action("Campaigns_Read", "Campaigns"))
      ));

在加载页面时调用的Index操作效果很好,但是当我尝试移至下一页时,会调用Camapigns_Read操作,但是会得到带有json结果的空白页面.我在这里想念什么?

the Index action that is called when the page is loaded works great, but when I try to move to the next page the Camapigns_Read action is called but I get a blank page with json results. What am I missing here?

我想在服务器端执行分页

Edit : i want to perform paging on server-side

推荐答案

知道了,

问题是必须首先使用相同的控制器名称初始化视图-该死的命名约定:), 我的解决办法是

the issue was that the view must be initialized first, with the same controller name - damn this naming convention :), my solution was

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]    
        public ActionResult Index([DataSourceRequest] DataSourceRequest request)
        {
           DataSourceResult result = GetAllCampaigns().ToDataSourceResult(request);
           return Json(result, JsonRequestBehavior.AllowGet);        
        }

这篇关于Kendo ui Grid显示json而不是网格Asp .net剃须刀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆