Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Candaele 1197 posts 2049 karma points
    May 03, 2012 @ 11:28
    Anthony Candaele
    0

    problem rendering html with Razor

    Hi,

    Although I much prefer Razor of Xslt, I'm still struggling a bit with rendering html with Razor.

    In a script file, I want to render this code:

    @(<href="@promotor.NiceUrl">@promotor.Name</a", ");

    But it won't save, the error says:

    error CS1525: Invalid expression term '<'

    Can someone help me out?

    Thanks a lot,
    Anthony

  • gilad 185 posts 425 karma points
    May 03, 2012 @ 11:38
    gilad
    1

    Hi. :)

    you dont need to add @(  for render html tag.

    Try this: 

    <href="@promotor.NiceUrl">@promotor.Name</a> ,

    if is not working please write the entire code blok.

    Cheers.

  • Fuji Kusaka 2203 posts 4220 karma points
    May 03, 2012 @ 11:44
    Fuji Kusaka
    1

    Hi Anthony,

    Try this instead.

    <a href="@promotor.Url">@promotor.Name</a>

    //fuji

  • Anthony Candaele 1197 posts 2049 karma points
    May 03, 2012 @ 11:44
    Anthony Candaele
    0

    Hi gilad

    I used '@(...);' because I also need to concatinate a space and a comma:  " ,"

    My entire code looks like this now:

    @if (Model.HasValue("Promotors"|Model.HasValue("externalPromotorName"))

     <span>Promotors:
       @if(Model.HasValue("Promotors"))
       {
        foreach (var id in @Model.Promotors)
         {
            dynamic promotor new DynamicNode(id.InnerText);
            if (id.IsLast(&!Model.HasValue("externalPromotorName"))
            {
             <href="@promotor.NiceUrl">@promotor.Name</a>
             }
            else
            {
             <href="@promotor.NiceUrl">@promotor.Name</a", ";
             }
         }
       }
       @if (Model.HasValue("externalPromotorName"))
       {
          @Model.externalPromotorName
        }
       </span>
    }

    As on would expect, this won't save, I get this error:

    Only assignment, call, increment, decrement, and new object expressions can be used as a statement

    Thanks for your help,
    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    May 03, 2012 @ 11:46
    Anthony Candaele
    0

    @fuji, our posts crossed, gilad also suggested this, but I need to concatenate a space and a comma:  " ," to the link

    thanks for your help

    Anthony

  • gilad 185 posts 425 karma points
    May 03, 2012 @ 11:57
    gilad
    1

    try this:

    foreach (var id in @Model.Promotors)
         {
            dynamic promotor new DynamicNode(id.InnerText);
             <href="@promotor.NiceUrl">@promotor.Name</a>
                   if (!id.IsLast() || Model.HasValue("externalPromotorName"))
    {
    @Html.Raw(", ");
         
         }

  • Anthony Candaele 1197 posts 2049 karma points
    May 03, 2012 @ 13:33
    Anthony Candaele
    0

    Hi gilad,

    yes, this works :)

    Thanks a lot,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft