MvcContrib GridModel : Is it possible to do ActionSyntax in a GridModel

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 04:35:19

问题


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:


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.



来源:https://stackoverflow.com/questions/1458782/mvccontrib-gridmodel-is-it-possible-to-do-actionsyntax-in-a-gridmodel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!