WebGrid不显示数据

时间:2017-07-12 10:01:15

标签: c# asp.net-mvc-4 webgrid

我的WebGrid没有显示绑定数据。我哪里错了?

//型号:

 public int UserId { get; set; }
        public string FromDate { get; set; }
        public string ToDate { get; set; }
        public IEnumerable<SelectListItem> UserList { get; set; }
        public List<UserReport> UserReports { get; set; }

//用户报告:

public class UserReport
    {
        public int SNo { get; set; }
        public string CustomerName { get; set; }
        public string Title { get; set; }
        public string CallType { get; set; }
        public string CallStatus { get; set; }
        public string Description { get; set; }
        public string Date { get; set; }
    }

//控制器:

 [HttpPost]
        public ActionResult Reports(ReportsModel model)
        {
            model.UserReports = _reportsModel.LoadUserReport(model);
            model.UserList = new SelectList(_reportsModel.LoadAllUsers(), "Value", "Text");
            return View(model);
        }

//检视:

@model MVCApp.Models.ReportsModel
@{
    ViewBag.Title = "Reports";
}


@using (Ajax.BeginForm("Reports", "Home", null, new AjaxOptions { OnBegin = "LoadStart", HttpMethod = "POST", OnSuccess = "OnSuccessfulSave()" }))
{
    <div class="container-fluid">
        <div id="errorStatus" style="display: none; width: 100%; margin: 0 auto; margin-top: 5px"></div>
        <div class="form-group">
            @Html.LabelFor(m => m.UserId, "User Name:")
            @Html.DropDownListFor(m => m.UserId, Model.UserList, "Select Name", new { @class = "form-control", @id = "ddlUserName", required = "required" })
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.FromDate, "From Date:")
            @Html.TextBoxFor(m => m.FromDate, new { @class = "form-control", @id = "txtFromDate", required = "required", type = "date" })
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.ToDate, "To Date:")
            @Html.TextBoxFor(m => m.ToDate, new { @class = "form-control", @id = "txtToDate", required = "required", type = "date" })
        </div>
        <input type="submit" class="btn btn-info" value="Generate Report" onclick="return Validate()" />
    </div>
}

@if (Model.UserReports.Count > 0)
{
    WebGrid grid = new WebGrid(source:Model.UserReports, rowsPerPage: 4);

    @grid.GetHtml( tableStyle: "table", // applying style on grid  

    fillEmptyRows: true,   
    //show empty row when there is only one record on page to it will display all empty rows there.  

    headerStyle: "header", //applying style.  

    footerStyle: "grid-footer", //applying style.  
    alternatingRowStyle: "webgrid-alternating-row",  
    rowStyle: "webgrid-row-style",  
    mode: WebGridPagerModes.All, //paging to grid   
    firstText: "<< First",  
    previousText: "< Prev",  
    nextText: "Next >",  
    lastText: "Last >>",  

    columns: new[]  // colums in grid  
    {  
        grid.Column("SNo"), //the model fields to display  
        grid.Column("CustomerName"),  
        grid.Column("Title"),  
        grid.Column("CallType"),  
        grid.Column("CallStatus"),  
        grid.Column("Description"),  
        grid.Column("Date")  
   })
}

调试我发现RowCount为6,但数据未显示在网格中。

0 个答案:

没有答案