So, simple question really. :)
I had this following code with ASPX View Engine:
<strong><%: ((City)Model.Location).Name %></strong>
Which renders Los Angeles
If i do this with Razor View Engine:
<strong>@((City)Model.Location).Name</strong> ^ | syntax highlighting stops here
It renders this:
(really huge object name must be .ToString).Name
So, the highlighting cuts off at Location), and it's treating the .Name code i have (which is a property on a City object) as pure HTML.
Why is it deeming the ) as the end of the Razor code block?
Any ideas?
Also - is there a Razor reference which has all the syntax/keywords? (it took me a while to figure out that <% Import Namespace
is @using
with Razor).
Thanks Guys!
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.
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.
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.
You can add support for Pages to any ASP.NET Core MVC app by simply adding a Pages folder and adding Razor Pages files to this folder. Razor Pages use the folder structure as a convention for routing requests.
Does <strong>@(((City)Model.Location).Name)</strong>
work? I think it's thinking the expression contained within @()
is closed.
Also, for slightly easier reading...
<strong>@( (Model.Location as City).Name )</strong>
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