2011-04-01 64 views
0

我在mVC2中使用此代码,它对我来说工作得很好。但是,当我把它转换成mvc3这段代码给我错误。请告诉我如何将其转换为mvC3。该代码是问题在MVC3中添加图像

<% Html.Grid(Model.MemberPagedList).Columns(column => { 
column.For(x => x.Id).Named("Id"); 
     column.For(x => x.message).Named("Message").Action(p => 
     { %> 
     <td> some image tag here 
     </td> 
        <td style="display: none; " id =<%= p.Id%>> 
        <%= p.LogMessage %> 
       </td> 

       <% }); 
     }).RowStart((p,row) => {  
      if (row.IsAlternate) { %> 
        <tr > 
      <% } else { %> 
       <tr> 
      <% } 
    }).Sort(Model.GridSortOptions).Attributes(@class => "table-list").Render(); %> 

我更换<% %>@但它无法正常工作。我无法理解我怎么写HTML代码,即<td>.....</td>

<td style="display: none;" id=<%= p.Id%>> 
    <%= p.LogMessage %> 
</td> 

在MVC3

+0

哪些错误是你得到了吗? – tugberk 2011-04-01 15:01:20

回答

1

你可以使用自定义列中的图像添加到MVCContrib电网:

@(Html 
    .Grid<MyViewModel>(Model.MemberPagedList) 
    .Columns(column => 
    { 
     column.For(x => x.Id); 

     column.For(x => x.LogMessage); 

     column 
      .Custom(
       @<text> 
        <span>@item.LogMessage</span> 
        <img src="@Url.Action("image", new { id = item.Id })" alt="" /> 
       </text> 
      ) 
      .Named("Message"); 
    }) 
    .Sort(Model.GridSortOptions) 
    .Attributes(new Hash(@class => "table-list")) 
)