views:

183

answers:

1

I have a code in my aspx file which uses ActionSyntax, and i want to use a GridModel instead, but i don't know how to do that.

Here is a sample of my aspx file :

<% 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(); %>

And i'd like to do :

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

But i don't know how to render this ActionSyntax part in a .cs file :

 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> <%});

Someone have any idea ?

Thanks.

+1  A: 

Ok i found the solution ! Here is an example for the column "PDF" :

In my GridModel :

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

And the GetPdfColumn() :

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

Simple as that.

LoSTxMiND
Maybe i could use delegates, but I didn't manage to use them.
LoSTxMiND