Using Razor how/can you write straight text with out wrapping it in some type of html tag?
Example (This works but adds extra span tags):
@{ var foo = true; } @if(foo) { <span>Yes</span> } else { <span>No</span> }
I'd like to keep my final markup as clean as possible and not have the extra tags.
Thanks!
Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine.
Listing 1: Rendering a Razor View to String from within a Controller. The RenderViewToString() method works by receiving a controller context and virtual view path (i.e., ~/views/item/page. cshtml ) and optional model data that are passed to the view.
Razor is a markup syntax for embedding . NET based code into webpages. The Razor syntax consists of Razor markup, C#, and HTML. Files containing Razor generally have a . cshtml file extension.
Razor is a simple programming syntax for embedding server code in web pages. Razor syntax is based on the ASP.NET framework, the part of the Microsoft.NET Framework that's specifically designed for creating web applications.
use the <text>
tags
@{ var foo = true; } @if(foo) { <text>Yes</text> } else { <text>No</text> }
The <text>
tag signals to the razor view engine to write the contents to the output.
Alternatively, you can use @:
@{ var foo = true; } @if(foo) { @:Yes } else { @:No }
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