devexpress mvc gridview加载无限

时间:2014-05-22 03:01:23

标签: c# asp.net-mvc asp.net-mvc-5 devexpress-mvc

我使用DevExpress MVC GridView。当我在DevExpress MVC GridView上单击编辑,新建,删除和页面时,我遇到问题,gridview显示无限的加载。

index.cshtml

@model System.Collections.IEnumerable

@{
    ViewBag.Title = "Index";
}
<h2>Index</h2>
@Html.Partial("GridViewPartial", Model)

GridViewPartial

@{
    var grid = Html.DevExpress().GridView(settings => {
        settings.Name = "GridView";
        settings.CallbackRouteValues = new { Controller = "GridView", Action = "GridViewPartial" };
        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "GridView", Action = "AddNewRecordToGrid" };
        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "GridView", Action = "DeleteRecordFromGrid" };
        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "GridView", Action = "UpdateRecordFromGrid" };
        settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;
        settings.SettingsEditing.PopupEditFormModal = true;

        settings.CommandColumn.ShowEditButton = true;
        settings.CommandColumn.ShowDeleteButton = true;
        settings.CommandColumn.ShowNewButton = true;
        settings.CommandColumn.Visible = true;

        settings.KeyFieldName = "CountryID";
        settings.Columns.Add("CountryCd");
        settings.Columns.Add("Description");

        settings.ClientLayout = (s, e) => {
            if (e.LayoutMode == ClientLayoutMode.Loading) {
                if (Session["GridState"] != null)
                    e.LayoutData = (string)Session["GridState"];
            } else
                Session["GridState"] = e.LayoutData;
        };
    });
    if (ViewData["EditError"] != null) {
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}
@grid.Bind(Model).GetHtml()

控制器

using DevExpress.Web.Mvc;
using WebApplication1.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApplication1.Controllers
{
    public class GridViewController : Controller
    {
        public ActionResult Index()
        {
            return View(CoreHRMDataProvider.GetEditableCountries());
        }
        public ActionResult GridViewPartial() {
            return PartialView("GridViewPartial", CoreHRMDataProvider.GetEditableCountries());
        }
        [HttpPost, ValidateInput(false)]
        public ActionResult AddNewRecordToGrid(EditableCountry country) {
            if (ModelState.IsValid) {
                try {
                    CoreHRMDataProvider.InsertCountry(country);
                } catch (Exception e) {
                    ViewData["EditError"] = e.Message;
                }
            } else
                ViewData["EditError"] = "Please, correct all errors.";
            return PartialView("GridViewPartial", CoreHRMDataProvider.GetEditableCountries());
        }
        [HttpPost, ValidateInput(false)]
        public ActionResult UpdateRecordFromGrid(EditableCountry country) {
            if (ModelState.IsValid) {
                try {
                    CoreHRMDataProvider.UpdateCountry(country);
                } catch (Exception e) {
                    ViewData["EditError"] = e.Message;
                }
            } else
                ViewData["EditError"] = "Please, correct all errors.";
            return PartialView("GridViewPartial", CoreHRMDataProvider.GetEditableCountries());
        }
        [HttpPost, ValidateInput(false)]
        public ActionResult DeleteRecordFromGrid(int countryID) {
            if (countryID >= 0) {
                try {
                    CoreHRMDataProvider.DeleteCountry(countryID);
                } catch (Exception e) {
                    ViewData["EditError"] = e.Message;
                }
            }
            return PartialView("GridViewPartial", CoreHRMDataProvider.GetEditableCountries());
        }
    }
}

为什么会这样? 我的问题的解决方案是什么?

由于

2 个答案:

答案 0 :(得分:0)

我认为你应该在布局页面上的devexpress脚本之前定义你的jquery脚本

答案 1 :(得分:0)

我猜这种情况正在发生,因为您没有从控制器获取模型。尝试像这样更改index.cshtml:

@{
    ViewBag.Title = "Index";
}
<h2>Index</h2>
@Html.Action("GridViewPartial")