我正在尝试使用帮助程序在 MVC3 中实现 JqGrid,但我一直收到一个 javascript 错误 - * “JavaScript 运行时错误:对象不支持属性或方法 'jqGrid'”。*我还在我的项目中添加了 MVCJqgrid 的引用。这是我在视图中的 Jqgrid 代码:-
@(Html.Grid("AgentGrid")
.SetCaption("Agents")
.AddColumn(new MvcJqGrid.Column("AgentId").SetLabel("Agent SSN"))
.AddColumn(new MvcJqGrid.Column("Name"))
.AddColumn(new MvcJqGrid.Column("Country"))
.AddColumn(new MvcJqGrid.Column("City"))
.AddColumn(new MvcJqGrid.Column("Title"))
.SetUrl(Url.Action("List", "Home"))
.SetAutoWidth(true)
.SetRowNum(10)
.SetViewRecords(true)
.SetPager("pager")
)
这是我在控制器中的操作代码:-
public ActionResult List(GridSettings gridSettings)
{
DataContext db = new DataContext();
string Name = string.Empty;
string Country = string.Empty;
string City = string.Empty;
string Title = string.Empty;
if (gridSettings.IsSearch)
{
Name = gridSettings.Where.rules.Any(r => r.field == "Name") ?
gridSettings.Where.rules.FirstOrDefault(r => r.field == "Name").data : string.Empty;
Country = gridSettings.Where.rules.Any(r => r.field == "Country") ?
gridSettings.Where.rules.FirstOrDefault(r => r.field == "Country").data : string.Empty;
City = gridSettings.Where.rules.Any(r => r.field == "City") ?
gridSettings.Where.rules.FirstOrDefault(r => r.field == "City").data : string.Empty;
Title = gridSettings.Where.rules.Any(r => r.field == "Title") ?
gridSettings.Where.rules.FirstOrDefault(r => r.field == "Title").data : string.Empty;
}
var Agents = db.Agent.ToList();
int totalAgents = Agents.Count;
var jsonData = new
{
total = totalAgents / gridSettings.PageSize + 1,
page = gridSettings.PageIndex,
records = totalAgents,
rows = (
from c in Agents
select new
{
id = c.AgentId,
cell = new[]
{ c.AgentId.ToString(),
string.Format("{0} {1}", c.Name, c.Country),
c.City,
c.Title
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
请建议我解决问题!提前致谢!!