Why am I required to use the <text>
tag to enclose the pipe literal '|' in this markup? Surely it is well outside the scope of the ActionLink method.
@foreach (var item in Model.DetailItem.PlannedResources)
{
<tr>
<td>
@if (Model.ViewMode == ViewMode.Edit)
{
@Html.ActionLink("Edit", "Edit", new { id = item.PlannedResourceId }) <text>|</text>
@Html.ActionLink("Delete", "Delete", new {id = item.PlannedResourceId})
}
@Html.ActionLink("Details", "Details", new { id = item.PlannedResourceId })
</td>
<td>
| @item.ResourceType.Name
</td>
</tr>
}
If I don't use it, I get the error CS1525: Invalid expression term '|'
, but the second '|' gets by unhindered.
Using @: to explicitly indicate the start of content We are using the @: character sequence to explicitly indicate that this line within our code block should be treated as content.
In Razor, `@` symbol is used to transition from HTML to C#. To escape an '@' symbol in razor markup, use two '@' symbols.
From the docs, "Razor Pages can make coding page-focused scenarios easier and more productive than using controllers and views." If your ASP.NET MVC app makes heavy use of views, you may want to consider migrating from actions and views to Razor Pages.
It's because when you are inside a statement with {
and }
only HTML tags are considered as literals, everything else is server side script. So you need to either use standard HTML tags such as <div>
, <span>
, ... or if you want to use a literal use the special <text>
tag which is not outputted to the response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With