【问题标题】:gridmvc not showing data from databasegridmvc 不显示数据库中的数据
【发布时间】:2023-04-10 12:45:01
【问题描述】:

我可以让我的网格显示,但无法让我的数据填充到单元格内。这是我的网格,看起来很完美。

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

                };

            })
        );
        
    }
}

但我的数据没有显示在列中。我已经按照 mvcgrid 网站上的指南进行了操作,这就是我需要做的所有事情才能在这里获取我的数据。这是我的 HTML:

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

    @Html.MVCGrid("Report_Actions")

</div>

【问题讨论】:

    标签: c# mvcgrid


    【解决方案1】:

    我只是自己回答这个问题,因为我终于找到了主要问题,即为什么我的数据没有显示并且它很愚蠢。因此,如果有人做同样的事情,希望这会在几年或几个月内找到喜欢的人。

    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
    

    在 .WithValueTemplate() 中,我删除了 div 和标签,一切正常。我没有引用正确的东西,所以它没有抛出错误,但它会在调试时停止。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 2018-11-16
      • 2016-04-22
      • 2021-11-06
      • 2015-04-04
      • 2019-10-31
      • 1970-01-01
      相关资源
      最近更新 更多