【问题标题】:Why isn't my razor helper being executed inside a Using statement?为什么我的剃刀助手没有在 Using 语句中执行?
【发布时间】:2013-02-22 02:03:59
【问题描述】:

这个观点:

@Using Html.BeginForm
    SimpleMessage
End Using

@Helper SimpleMessage()
    @<p>This is a simple message</p>
End Helper

结果

<form action="/Controller/Action" method="post"></form>

但是

@* Now let's not call it from within a using *@
@SimpleMessage

@Helper SimpleMessage()
    @<p>This is a simple message</p>
End Helper

结果

<p>This is a simple message</p>

为什么我的助手在我的Using Html.BeginForm 中不工作?

【问题讨论】:

  • 这是一个纯粹的猜测,因为我对 Razor 知之甚少,但是如果你在 using 中使用 @ 前面的 SimpleMessage 符号会发生什么?
  • 你明白了!我怎么错过了?我想,由于我在代码中,我不需要@ 来调用函数,这是真的,但显然你是为剃须刀助手做的。
  • @jpmc26,我认为你说对了一半。我认为他也需要 ()
  • VB.NET 中不需要括号,尽管我可能会添加它们以保持一致性:)
  • Ahaaa...是的,过去 3 年我只在 c# 中度过了

标签: asp.net-mvc vb.net asp.net-mvc-3 razor


【解决方案1】:

你需要@符号在辅助方法前面。

@Using Html.BeginForm
    @SimpleMessage
End Using

【讨论】:

    猜你喜欢
    • 2012-08-16
    • 1970-01-01
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    • 2011-05-07
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多