In my project i try to add grid but its showing following error 'HtmlHelper>' does not contain a definition for 'Grid' and the best extension method overload 'MvcGridExtensions.Grid(IHtmlHelper, IEnumerable)' requires a receiver of type 'IHtmlHelper'
Code:
@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()
)
What am doing wrong here?
The problem occurred because
NonFactors.Grid.Mvc6package usesIHtmlHelperinterface derived fromMicrosoft.AspNetCore.Mvc.Renderingnamespace, while the grid should useHtmlHelperclass fromSystem.Web.Mvcnamespace, hence the package is incompatible with MVC 5.I suggest you to uninstall
NonFactors.Grid.Mvc6package (since it designed for ASP.NET Core MVC) and useNonFactors.Grid.Mvc5package instead, by using Package Manager or console command:Note:
You can compare the contents of
Gridextension method in MVC 5 and Core MVC version, which proves different namespace usage.Related issue:
MVC:- Integration of mvc6.grid