ASP.NET MVC 3 Razor语法-投射 [英] ASP.NET MVC 3 Razor Syntax - Casting
问题描述
所以,确实是一个简单的问题. :)
So, simple question really. :)
我在 ASPX View Engine 中使用了以下代码:
I had this following code with ASPX View Engine:
<strong><%: ((City)Model.Location).Name %></strong>
哪个渲染 洛杉矶
如果我使用 Razor View Engine:
<strong>@((City)Model.Location).Name</strong>
^
|
syntax highlighting stops here
它呈现以下内容:
(真正的大对象名称必须是.ToString).名称
因此,突出显示在 Location(地点)处被切断,并且正在处理我拥有的 .Name 代码(这是城市上的一个属性>对象)作为纯HTML.
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.
为什么将)视为Razor代码块的结尾?
Why is it deeming the ) as the end of the Razor code block?
有什么想法吗?
还-是否有包含所有语法/关键字的Razor参考? (花了我一段时间才发现Razor中的<% Import Namespace
是@using
).
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).
谢谢你们!
推荐答案
<strong>@(((City)Model.Location).Name)</strong>
是否有效?我认为这是因为@()
中包含的表达式已关闭.
Does <strong>@(((City)Model.Location).Name)</strong>
work? I think it's thinking the expression contained within @()
is closed.
这篇关于ASP.NET MVC 3 Razor语法-投射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!