【发布时间】:2018-07-27 02:47:42
【问题描述】:
我正在尝试使用 Grid.MVC 从我的数据库中提取到另一个视图的局部视图。我在 EditorTemplates 中创建的空视图中有以下内容:
@{
Layout = null;
}
@using GridMvc.Html
@using Inventory.Entities
@Html.Grid(Model).Columns(columns =>
{
columns.Add().Encoded(false).Sanitized(false).SetWidth(30).RenderValueAs(o => Html.CheckBox("Checked", false));
columns.Add(c => c.ProdName);
columns.Add(c => c.ProdID, true);
})
我有一个控制器,如下所示:
using Inventory.Entities;
using Inventory.Web.DataContext;
namespace Inventory.Web.Controllers
{
public class ProductionController : Controller
{
private CommonDB db = new CommonDB();
// GET: Production
public ActionResult Production(string prodGrid)
{
var ProdList = new List<string>();
var ProdQry = from p in db.Productions
select p.ProdName;
ProdList.AddRange(ProdQry.Distinct());
ViewBag.prodGrid = new SelectList(ProdList);
return View(prodGrid);
}
}
}
模型如下:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace Inventory.Entities
{
public class Production
{
[Key]
public int ProdID { get; set; }
[Required]
public string ProdName { get; set; }
}
}
我使用 NuGet 包管理器将 Grid.MVC 添加到解决方案中,并在 @Scripts.Render("~/bundles/modernizer") 之后将以下内容添加到 _Layout.cshtml:
<script src="@Url.Content("~/Scripts/jquery.min.js")" type="text/javascript"> </script>
<link href="@Url.Content("~/Content/Gridmvc.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/gridmvc.min.js")" type="text/javascript"> </script>
我检查并在参考资料中引用了 GridMVC,以及它所需的所有其他文件。不幸的是,我抛出了以下错误: 错误 1 找不到类型或命名空间名称“GridMvc”(您是否缺少 using 指令或程序集引用?)
错误 2“System.Web.Mvc.HtmlHelper”不包含“Grid”的定义,并且找不到接受“System.Web.Mvc.HtmlHelper”类型的第一个参数的扩展方法“Grid”(是您缺少 using 指令或程序集引用?)
我已经检查了文档和各种网站,试图找出问题所在,但我很困惑。有谁看到我可能在哪里做错了什么?现在这是我整个项目的阻碍。
提前谢谢你,
迈克尔·马斯特罗
【问题讨论】:
-
您是否检查了根目录和视图文件夹中 web.config 文件中的
<pages部分。这些应该有命名空间的关系 -
它在根文件夹的web.config中。它显示:
-
我猜一个或多个 js 文件没有正确呈现。如果您运行该页面并按 f12,您能否验证脚本确实存在?