Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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:
@(<a 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
Hi. :)
you dont need to add @( for render html tag.
Try this:
<a href="@promotor.NiceUrl">@promotor.Name</a> ,
if is not working please write the entire code blok.
Cheers.
Hi Anthony,
Try this instead.
<a href="@promotor.Url">@promotor.Name</a>
//fuji
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")) { <a href="@promotor.NiceUrl">@promotor.Name</a> } else { <a 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
@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
try this:
foreach (var id in @Model.Promotors) { dynamic promotor = new DynamicNode(id.InnerText); <a href="@promotor.NiceUrl">@promotor.Name</a> if (!id.IsLast() || Model.HasValue("externalPromotorName")){@Html.Raw(", ");} }
Hi gilad,
yes, this works :)
Thanks a lot,
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
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:
@(<a 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
Hi. :)
you dont need to add @( for render html tag.
Try this:
<a href="@promotor.NiceUrl">@promotor.Name</a> ,
if is not working please write the entire code blok.
Cheers.
Hi Anthony,
Try this instead.
//fuji
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"))
{
<a href="@promotor.NiceUrl">@promotor.Name</a>
}
else
{
<a 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
@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
try this:
foreach (var id in @Model.Promotors)
{
dynamic promotor = new DynamicNode(id.InnerText);
<a href="@promotor.NiceUrl">@promotor.Name</a>
if (!id.IsLast() || Model.HasValue("externalPromotorName"))
{
@Html.Raw(", ");
}
}
Hi gilad,
yes, this works :)
Thanks a lot,
Anthony
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.