我想在MVC3中使用幫助器實現JqGrid,但所有的時間我都得到一個javascript錯誤 - * 「JavaScript運行時錯誤:對象不支持屬性或方法'jqGrid'「。 *我也在我的項目中添加了MVCJqgrid的引用。 這裏是我的jqGrid代碼視圖: -獲取errorJavaScript運行時錯誤:對象不支持MVC 3中使用幫助器的屬性或方法'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);
}
請建議我要解決這個問題! 在此先感謝!