【问题标题】:While Create gridview using grid.Mvc6 showing error使用 grid.Mvc6 创建 gridview 时显示错误
【发布时间】:2019-07-29 06:55:46
【问题描述】:

在我的项目中,我尝试添加网格,但它显示以下错误 'HtmlHelper>' 不包含“网格”的定义和最佳扩展方法重载 “MvcGridExtensions.Grid(IHtmlHelper, IEnumerable)”需要“IHtmlHelper”类型的接收器

代码:

@model IEnumerable<SCM_MVC.Models.XXXXX>
@using NonFactors.Mvc.Grid;

        @(Html
                .Grid(Model)
                .Build(columns =>
                {
                    columns.Add(model => model.select).Titled("Name");
                    columns.Add(model => model.Surname).Titled("Surname");
                    columns.Add(model => model.MaritalStatus).Titled("Marital status");

                    columns.Add(model => model.Age).Titled("Age");
                    columns.Add(model => model.Birthday).Titled("Birthday").Formatted("{0:d}");
                    columns.Add(model => model.IsWorking).Titled("Employed");
                })
                .Empty("No data found")
                .Filterable()
                .Sortable()
                .Pageable()
        )

这里做错了什么?

【问题讨论】:

    标签: asp.net-mvc-5 mvcgrid


    【解决方案1】:

    出现问题是因为NonFactors.Grid.Mvc6 包使用从Microsoft.AspNetCore.Mvc.Rendering 命名空间派生的IHtmlHelper 接口,而网格应该使用来自System.Web.Mvc 命名空间的HtmlHelper 类,因此该包与MVC 5 不兼容。

    我建议你卸载 NonFactors.Grid.Mvc6 包(因为它是为 ASP.NET Core MVC 设计的)并改用 NonFactors.Grid.Mvc5 包,通过使用包管理器或控制台命令:

    Uninstall-Package NonFactors.Grid.Mvc6
    Install-Package NonFactors.Grid.Mvc5
    

    注意:

    您可以比较MVC 5Core MVC版本中Grid扩展方法的内容,证明不同的命名空间用法。

    相关问题:

    MVC:- Integration of mvc6.grid

    【讨论】:

    • 它可以工作,但我需要复选框列,这就是我尝试移动 mvc6 的原因
    猜你喜欢
    • 2014-05-22
    • 2022-01-14
    • 2018-05-02
    • 1970-01-01
    • 2019-02-13
    • 1970-01-01
    • 2019-02-06
    • 2023-01-06
    • 2023-02-03
    相关资源
    最近更新 更多