Using with Dependency Injection

Id First Name Last Name
370PatrickAdams
493KarenAdams
570NancyAdams
599EricAdams
635ChristineAdams
663BonnieAdams
778RonaldAdams
820SeanAdams
897JudithAdams
857MichaelAlexander
Showing 1 to 10 of 1000 entries

Code

Inside MVCGridConfig.cs
MVCGridDefinitionTable.Add("DIGrid", new MVCGridBuilder<Person>(colDefauls)
    .WithAuthorizationType(AuthorizationType.AllowAnonymous)
    .AddColumns(cols =>
    {
        cols.Add("Id").WithSorting(false)
            .WithValueExpression(p => p.Id.ToString());
        cols.Add("FirstName").WithHeaderText("First Name")
            .WithValueExpression(p => p.FirstName);
        cols.Add("LastName").WithHeaderText("Last Name")
            .WithValueExpression(p => p.LastName);
    })
    .WithSorting(true, "LastName")
    .WithPaging(true, 10)
    .WithRetrieveDataMethod((context) =>
    {
        var options = context.QueryOptions;
        int totalRecords;
        var repo = DependencyResolver.Current.GetService<IPersonRepository>();
        var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
            options.SortColumnName, options.SortDirection == SortDirection.Dsc);
        return new QueryResult<Person>()
        {
            Items = items,
            TotalRecords = totalRecords
        };
    })
);
View
@Html.MVCGrid("DIGrid")