0
votes

this is the latest mvc 5.2

here is the helper from code used from a forgotten blog years ago

    public static void SeriesSplitter<T>(this System.Web.Mvc.HtmlHelper htmlHelper, IEnumerable<T> items,
                                         int itemsBeforeSplit, Action<T> template, Action seriesSplitter)
    {
        if (items == null)
            return;
        if (items.Count() == 0)
            return;
        var i = 0;
        foreach (var item in items)
        {
            if (i != 0 && i % itemsBeforeSplit == 0)
                seriesSplitter();
            template(item);
            i++;
        }
    }

I use it like this

 <table class="public-photo" >  
  <tr class="public-photo">    
       <% Html.SeriesSplitter(Model.Photos, 6, item => { %>              
          <td class="public-photo">

          <a href="/Anon/DisplayPublicPhoto/?filename=<%=item.PublicFileName%>"  class="public-photo" >
       <%if(Model.HighRes == true){%>       
        <img src="/t2/<%=item.PublicFileName%>" id="<%=item.PublicFileName%>"  class="public-photo" alt="thumbnail" width="140" height="105"  />
         <%}
         else
         {%>
        <img src="/t/<%=item.PublicFileName%>" id="<%=item.PublicFileName%>"  class="public-photo" alt="thumbnail" width="140" height="105"  />

        <% }  %>
        </a>
        <a href="#" class="ReportPhoto" id="<%=item.PhotoID%>">Report this</a>
        </td>
                   <%}, () => { %>
  </tr>
   <tr>
      <% }); %>  
   </tr>
        </table>   

No problems in aspx but razor seems to choke on the last part of the action parameter where html code is interpersed with code. for razor I converted it to the correct syntax EDIT Razor code

<table class="public-photo">
    <tr class="public-photo">
        @Html.SeriesSplitter(Model.Photos, 6,  icetem =>
         { 
            @<td class="public-photo">

    <a href="/Anon/DisplayPublicPhoto/[email protected] " class="public-photo">
        @if (Model.HighRes == true)
                     {
            <img src="/t2/@icetem.PublicFileName" id="@icetem.PublicFileName" class="public-photo" alt="thumbnail" width="140" height="105" />

                     }
       else
         {
            <img src="/t/@icetem.PublicFileName" id="@icetem.PublicFileName" class="public-photo" alt="thumbnail" width="140" height="105" />

            }
    </a>
    <a href="#" class="ReportPhoto" id="@icetem.PhotoID">Report this</a>
</td>;
       },
       () => {
   //</tr>
   // <tr>
        });
    </tr>
</table>

the error is CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

2
Is there an error message? That seems pretty important. Otherwise, what is the result? It looks like you've given us only your Web Forms code. Where's your Razor code? - mason
hold on found a similar question here stackoverflow.com/questions/4883034/… - Joe
@Joe Which line is your error occurring at? - mason
this line will throw error @<td class="public-photo"> remove the "@" or replace with "@:" - Scott Selby
try removing semicolon at the end of your expression.. - gunvant.k

2 Answers

0
votes

use @item.PublicFileName not <%=item.PublicFileName%> and use @: or <text></text> to render html tags

0
votes

All HTML helper method are used to generate UI so it should always return String.your Helper method is not returning anything. please check following article from MSDN.