Last Tab Content repeated in all tabs - ASP.NET MVC using Razor engine (CSHTML)

1 posts, 0 answers
  1. Prabhat
    Prabhat avatar
    1 posts
    Member since:
    Aug 2012

    Posted 02 Aug 2012 Link to this post

    Hi
    Using the TabStrip UI element in our ASP.NET MVC 3 application using the Razor engine and binding the control to an IEnumerable<T> we noticed the following behaviour.
    • Using a FOR loop on the IEnumerable<T> to generate the Tab Items (Tab pages) works fine
    • But setting the Tab Item Content within the same loop for some reason causes some kind of a deferred execution, the contents seem to be set after the tab pages are created (which I assume is related to the load-on-demand feature of the tabstrip)
    • The problem is, the iteration seem to be using the last element in the model to set the content of all the tab pages.

    Here is the sample code, could you please direct to the mistake in it or the right method using razor to acheive the same.

    @model IEnumerable<KendoMVCExample.Models.CustomerAddress>
    ...
    @(Html.Kendo().TabStrip()
        .Name("CustomerAddressTabStrip")
        .Items(items =>
        {
            foreach (var customer in Model)
            {
                items.Add()
                .Content(@<text> @RenderTableContent(customer) </text>)//<----this fails {last address is repeated on all} 
                .Text(customer.CustomerName); //<----this works fine 
            }        
        }).SelectedIndex(0)
        )
     
         @helper RenderTableContent(KendoMVCExample.Models.CustomerAddress customer)
             {
              <table>
                 <tr>
                     <td>
                         @customer.AddressLine1<br />
                         @customer.AddressLine2<br />
                         @customer.AddressLine3<br />
                     </td>
                 </tr>
             </table>
        }
Back to Top