I have the following snippet:
<ul>
@foreach (var product in Model.Products)
{
<li>@product.Name [email protected]</li>
}
</ul>
It treats [email protected] as a literal. How can I have a character placed right before the @ symbol?
Code block is used to enclose C# code statements. It starts with @ (at) character and is enclosed by {} (curly braces). Unlike expressions, C# code inside code blocks is not rendered.
Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML. It's just that ASP.NET MVC has implemented a view engine that allows us to use Razor inside of an MVC application to produce HTML.
razor helps you embed serverside code like C# code into web pages. cshtml is just a file extension. razor view engine is used to convert razor pages(. cshtml) to html.
That scenario is there to allow [email protected]
(emails) to exist unmolested in existing markup. Instead, use:
x@(product.Count)
(the extra brackets immediately after @
, i.e. @(...)
indicate an explicit code expression)
or better html-wise:
×@(product.Count)
You might also then find this works conveniently:
×@product.Count
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