MvcContrib GridModel:是否可以在GridModel中执行ActionSyntax

时间:2009-09-22 08:26:32

标签: c# asp.net asp.net-mvc mvccontrib

我的aspx文件中有一个使用ActionSyntax的代码,我想使用GridModel,但我不知道该怎么做。

以下是我的aspx文件示例:

<% Html.Grid(ViewData.Model).Columns(column => {
   column.For(x => x.Id).Named("N° de contrat");
   column.For(x => x.SubscriptionDate).Format("{0:d}").Named("Date de souscription");
   column.For(x => x.SubscriptionOrigin).Named("Source");
   column.For(x => x.Agent).Named("Agence(*)");
   column.For(x => x.Agent).Named("Agent");
   column.For(x => x.Subscriber).Named("Souscripteur");
   column.For(x => x.ProductTitle).Named("Produit");
   column.For(x => x.NbBeneficiaries).Named("Nombre de bénéficiaires");
   column.For(x => x.Price).Named("Montant du contrat");
   column.For("PDF").Named("").Action(p => {%> <td><img src="../Content/Images/pdf.gif" /></td> <%});
   column.For("Mail").Named("").Action(p => {%> <td><img src="../Content/Images/mail.gif" /></td> <%});
   column.For("Attestation").Named("").Action(p => {%> <td><img src="../Content/Images/attestation.gif" /></td> <%});
   column.For("Poubelle").Named("").Action(p => {%> <td><img src="../Content/Images/poubelle.png" /></td> <%});
   }).Attributes(id => "subList").Render(); %>

我想这样做:

<%= Html.Grid(ViewData.Model).WithModel(new MyGridModel()) %>

但我不知道如何在.cs文件中呈现此ActionSyntax部分:

 column.For("PDF").Named("").Action(p => {%> <td><img src="../Content/Images/pdf.gif" /></td> <%});
 column.For("Mail").Named("").Action(p => {%> <td><img src="../Content/Images/mail.gif" /></td> <%});
 column.For("Attestation").Named("").Action(p => {%> <td><img src="../Content/Images/attestation.gif" /></td> <%});
 column.For("Poubelle").Named("").Action(p => {%> <td><img src="../Content/Images/poubelle.png" /></td> <%});

有人有任何想法吗?

感谢。

1 个答案:

答案 0 :(得分:2)

好的,我找到了解决方案!以下是“PDF”列的示例:

在我的GridModel中:

Column.For("PDF").Named("").Action(p => GetPdfColumn());

GetPdfColumn():

private void GetPdfColumn()
    {
        HttpContext.Current.Response.Write(@"<td><img src='../Content/Images/pdf.gif' /></td>"); 
    }

这很简单。