【问题标题】:Access Model Data in WebGrid在 WebGrid 中访问模型数据
【发布时间】:2019-02-12 19:38:57
【问题描述】:

如何访问 WebGrid 中的其他子模型信息?

var personGrid = new WebGrid(source: Model.People,
        ajaxUpdateContainerId: "personGrid",
        ajaxUpdateCallback: "jQueryTableStyling",
        defaultSort: "PersonID");

@personGrid.GetHtml(
        tableStyle: "webgrid",
        headerStyle: "webgrid-header",
        footerStyle: "webgrid-footer",
        alternatingRowStyle: "zebra",
              columns: personGrid.Columns(
                   personGrid.Column("PersonID", "Person ID"),
                   personGrid.Column("Name", "Name"),
                   // This line isn't working and I'm not sure how to get it to work.
                   personGrid.Column(model => model.Career.Title) 
               )
        )

【问题讨论】:

    标签: asp.net-mvc-3 entity-framework-4 webgrid


    【解决方案1】:

    试试:

    personGrid.Column(format: @<text>@item.Career.Title</text>) 
    

    【讨论】:

      【解决方案2】:

      @模型列表

      WebGrid grid = new WebGrid(Model, canPage: true, canSort: true, rowsPerPage: 10, ajaxUpdateContainerId: "divDataList");
      
      <div id="divDataList">
          @grid.GetHtml(tableStyle: "table-user-information table table-bordered table-striped",
              headerStyle: "webgrid-header",
              fillEmptyRows: false,
              mode: WebGridPagerModes.All,
              firstText: "<< First",
              previousText: "< Prev",
              nextText: "Next >",
              lastText: "Last >>",
              columns: grid.Columns(
              grid.Column(header: "S No.", style: "white", format: item => item.WebGrid.Rows.IndexOf(item) + 1 + Math.Round(Convert.ToDouble(grid.TotalRowCount / grid.PageCount) / grid.RowsPerPage) * grid.RowsPerPage * grid.PageIndex),
      

      grid.Column(columnName: "registrationNo", header: "Application No.", format: @@item.registrationNo), grid.Column("progressReportSubject", header: "进度报告主题"), grid.Column("uploadDate", header: "上传日期"), grid.Column(columnName: "progressReportPath", header: "进度报告", format: @ @if (!string.IsNullOrEmpty(@item.progressReportPath)) { } 别的 {

          }
          </text>)
      
              ))
      </div>
      

      }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-15
        • 1970-01-01
        • 2017-05-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-06
        相关资源
        最近更新 更多