Regarding Razor expression usage (ASP.Net) cases, there are two cases commonly met:
<div title="@MyClass.Test"></div>
and
<div [email protected]></div>
As they both seem to work the same on Razor 2.0, I would like to know if there are any differences, especially in corner cases (null/malfored values etc).
Eventually I would also like to know which is best as a practice to follow. Thank you in advance.
Razor Expression Encoding Razor provides expression encoding to avoid malicious code and security risks. In case, if user enters a malicious script as input, razor engine encode the script and render as HTML output.
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.
The Razor syntax consists of Razor markup, C#, and HTML. Files containing Razor generally have a . cshtml file extension.
What is Razor? Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages. Server-based code can create dynamic web content on the fly, while a web page is written to the browser.
The rules for HTML attributes can be found here. The quotes are usually optional, but if there is a space in the value of MyClass.Test
then you'll need them.
I would say best practice is to include them as it doesn't hurt and will save you problems if there are spaces in the value.
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