代码之家  ›  专栏  ›  技术社区  ›  RPM1984

ASP.NET MVC 3 Razor语法-强制转换

  •  23
  • RPM1984  · 技术社区  · 14 年前

    所以,简单的问题真的。:)

    我有以下代码 ASPX视图引擎 :

    <strong><%: ((City)Model.Location).Name %></strong>
    

    哪个渲染 洛杉矶

    如果我这样做 Razor View引擎:

    <strong>@((City)Model.Location).Name</strong>
                                 ^
                                 |
    syntax highlighting stops here
    

    它呈现出:

    (真正巨大的对象名必须是.ToString).name

    因此,突出显示在 位置) 它正在治疗 名字 我拥有的代码(这是 西蒂 对象)作为纯HTML。

    为什么它认为 ) 作为Razor代码块的结尾?

    有什么想法吗?

    还有-是否有一个包含所有语法/关键字的Razor引用?(我花了一段时间才弄明白 <% Import Namespace @using 用剃刀)。

    谢谢你们!

    2 回复  |  直到 13 年前
        1
  •  44
  •   John Sheehan    14 年前

    <strong>@(((City)Model.Location).Name)</strong> 工作?我想它是在想 @() 已关闭。

        2
  •  11
  •   Dean Thomas    13 年前

    另外,为了更容易阅读…

    <strong>@( (Model.Location as City).Name )</strong>