我之前问过类似的问题:如何使用 mvc 3 aspx 引擎创建动态网格?(请不要忽略上一个问题)
如果我写下面的代码结果第一张图片:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumarable<MvcAppGridView.Models.Employee>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
var grid = new WebGrid(source: Model, defaultSort: "FirstName", rowsPerPage: 3);
using (Html.BeginForm())
{
%>
<div>
<%: grid.GetHtml(columns: grid.Columns(
grid.Column(
header: "",
style: "text-align-center",
format: (item) => new HtmlString(Html.ActionLink("Edit", "Edit", new { id = item.id }).ToString() + " | " +
Html.ActionLink("Details", "Details", new { id = item.id }).ToString() + " | " +
Html.ActionLink("Delete", "Delete", new { id = item.id }).ToString()
)
)
))
%>
</div>
<%} %>
</asp:Content>
但我想动态地喜欢:
<%:grid.GetHtml(tableStyle:"grid",
headerStyle:"head",
alternatingRowStyle:"alt",
columns:grid.Columns(
grid.Column("FirstName"),
grid.Column("LastName"),
grid.Column("Salary"),
grid.Column(
header: "",
style: "text-align-center",
format: (item) => new HtmlString(Html.ActionLink("Edit", "Edit", new { id = item.id }).ToString() + " | " +
Html.ActionLink("Details", "Details", new { id = item.id }).ToString() + " | " +
Html.ActionLink("Delete", "Delete", new { id = item.id }).ToString()
)
))) %>
我的愿望结果是这样的:
但我不喜欢下面的绑定:
grid.Column("FirstName"),
grid.Column("LastName"),
grid.Column("Salary"),
不喜欢!我想自动或动态地获得第二个结果,但如何?