Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Razor syntax error

how i can translate this code into razor syntax:

<% for (int i = 0; i < items.Length; i++)  %>
<%{
    if (i % 3 == 0)
    { %>
      <tr>
 <% } %>
    <td><a href="<%: url[i] %>"><%: title[i] %></a></td>           
 <% if (i % 3 == 2)
    { %>
      </tr>        
 <% } %>
<%} %>

i'm try, but not success:

@for (int i = 0; i < items.Length; i++) 
{
    if (i % 3 == 0) 
    { 
        <tr>
    }
    <td><a href="@(url[i])">@(title[i])</a></td>
    if (i % 3 == 2) 
    {
        </tr>
    }
}
like image 406
Boo Avatar asked Dec 19 '25 04:12

Boo


1 Answers

i have find solution:

    @for (int i = 0; i < items.Length; i++)
{
    if (i % 3 == 0)
    {
@:<tr>
    }
    <td><a href="@url[i]"><img height="@(48 * Scale.Value)" width="@(48 * Scale.Value)" src="/i@(Scale.Value)/@(items[i]).png"/><span>@text[i]</span></a></td>
    if (i % 3 == 2)
    {
@:</tr>
    }
}

here is introduction to razor syntax, but:

Use the @: operator or the <text> element. The @: outputs a single line of content containing plain text or unmatched HTML tags; the element encloses multiple lines to output. These options are useful when you don’t want to render an HTML element as part of the output.

i don't know, why <text> now working. maybe because razor still RC, not release

like image 197
Boo Avatar answered Dec 20 '25 18:12

Boo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!