WebGrid不显示数据

时间:2013-02-01 10:09:53

标签: c# asp.net webgrid

我正在使用asp.net mvc3(c#)中的WebGrid。 我已完成所有编码,但我不知道为什么WebGrid不在页面上呈现。 我不知道我做错了什么。我已经调试了代码和数据

var grid = new WebGrid(source: Model, defaultSort: "CRM_ID");%>

但是,它没有显示。

这是我的ASPX页面代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<CRMEvent.Models.CRM.DatabaseEntities.CRM_Dashboard_Requests>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Dashboard
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Dashboard</h2>
    <%    
        var grid = new WebGrid(source: Model, defaultSort: "CRM_ID");%>
<div id="grid">

    <%
        grid.GetHtml(columns: grid.Columns(
          grid.Column(columnName: "CRM_ID",header: "CRM ID", canSort: true),
         grid.Column(columnName: "MDLNO", header: "MDLNO", canSort: true),
         grid.Column(columnName: "EMP_Name", header: "Employee", canSort: true),
         grid.Column(columnName: "SERVICE_TYPE", header: "Service Type", canSort: true),
         grid.Column(columnName: "Requested_Amount", header: "Requested Amount", canSort: true),
         grid.Column(columnName: "Created_Date", header: "Date", canSort: true)
         ));
   %>
    </div>
</asp:Content>

1 个答案:

答案 0 :(得分:1)

试试这样。 <%=

<%= grid.GetHtml(columns: grid.Columns(
          grid.Column(columnName: "CRM_ID",header: "CRM ID", canSort: true),
         grid.Column(columnName: "MDLNO", header: "MDLNO", canSort: true),
         grid.Column(columnName: "EMP_Name", header: "Employee", canSort: true),
         grid.Column(columnName: "SERVICE_TYPE", header: "Service Type", canSort: true),
         grid.Column(columnName: "Requested_Amount", header: "Requested Amount", canSort: true),
         grid.Column(columnName: "Created_Date", header: "Date", canSort: true)
         )); %>

甚至<%: %>这种语法用于html编码。