themagician
themagician

Reputation: 13

gridmvc not showing data from database

I am able to get my grid to show up but cannot get my data to populate inside of the cells. Here is my grid and it looks perfect.

public static class MVCGridConfig 
{
    public static void RegisterGrids()
    {
        

        MVCGridDefinitionTable.Add("Report_Actions", new MVCGridBuilder<FMB_Reports_AllInfo_Result>()
            .WithAuthorizationType(AuthorizationType.AllowAnonymous)
            .AddColumns(cols =>
            {
                // Add your columns here
                cols.Add("Id").WithSorting(true)
                    .WithValueTemplate("<div><label>ID:</label>{Model1.PickupPath}")
                    .WithHeaderText("User ID").WithHtmlEncoding(false)
                    .WithValueExpression(p => p.Id.ToString()); // use the Value Expression to return the cell text for this column
                cols.Add("PickupPath").WithColumnName("File Location")
                    .WithValueTemplate("{Model.PickupPath}")
                    .WithHeaderText("File Locations")
                    .WithValueExpression(p => p.PickupPath);
                cols.Add("ReportDescription").WithColumnName("Report Name")
                    .WithHeaderText("Report Name")
                    .WithValueExpression(p => p.ReportDescription);
                cols.Add("DropOffPath").WithColumnName("File Destination")
                    .WithHeaderText("File Destination")
                    .WithValueExpression(p => p.DropOffPath);
                cols.Add("Active").WithColumnName("Active")
                    .WithHeaderText("Active")
                    .WithValueExpression(p => p.Active.ToString());
                cols.Add("TimeAccessed").WithColumnName("Time Accessed")
                    .WithHeaderText("Time Accessed")
                    .WithValueExpression(p => p.TimeAccessed.ToString());
                

            })
            //.WithNoResultsMessage("<div class='pad-left-20'>There are no items.</div>")
            .WithPaging(true, 30)
            .WithRetrieveDataMethod((context) =>
            {
                var options = context.QueryOptions;
                var result = new QueryResult<FMB_Reports_AllInfo_Result>();
              
                return new QueryResult<FMB_Reports_AllInfo_Result>()
                {
                    Items = new List<FMB_Reports_AllInfo_Result>(),
                    TotalRecords = 0 // if paging is enabled, return the total number of records of all pages

                };

            })
        );
        
    }
}

But my data does not show in the columns. I have follwed the guides from the mvcgrid website and this is all it shows that I should need to do to get my data in here. Here is my HTML:

@using MVCGrid.Web;
<div class="panel-body">

    @Html.MVCGrid("Report_Actions")

</div>

Upvotes: 0

Views: 84

Answers (1)

themagician
themagician

Reputation: 13

Im only answering this myself because I finally found out the main issue as to why my data wasn't showing and it was dumb. So hopefully this will find someone fancy in a couple years or months if someone does the same thing.

cols.Add("Id").WithSorting(true)
                .WithValueTemplate("<div><label>ID:</label>{Model1.PickupPath}")
                .WithHeaderText("User ID").WithHtmlEncoding(false)
                .WithValueExpression(p => p.Id.ToString()); // use the Value

In the .WithValueTemplate() I deleted the div and labels and everything worked perfect. I wasn't referencing the right stuff so it wasn't throwing an error but it would just stop on this when debugging.

Upvotes: 1

Related Questions