asp.net-mvc ASP.NET MVC 内联 Razor 变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9614896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET MVC inline Razor variable
提问by pistacchio
In pre-Razor MVC I could write this in a view:
在 Razor MVC 之前,我可以在一个视图中写这个:
<span>I want to write in<%= myVariable %>side</span>
In Razor, of course I can't
在剃刀中,我当然不能
<span>I want to write in@myVariableside</span>
bacause the template engine would look for the variable @myVariableside. How to solve this? Thanks
因为模板引擎会寻找变量@myVariableside。如何解决这个问题?谢谢
回答by Andras Zoltan
First - have you tried it?
首先 - 你试过吗?
Secondly - if the interpreter has issues - you can try @(myVariableside).
其次——如果口译员有问题——你可以试试@(myVariableside)。
Equally if the variable name you're talking about is @name- then once you're inside the parentheses everything's fine, because the interpreter knows it's parsing C#/VB: @(@myVariableside)
同样,如果您正在谈论的变量名称是@name- 那么一旦您在括号内,一切都很好,因为解释器知道它正在解析 C#/VB:@(@myVariableside)
回答by Brunner
You can use <span>I want to write in@(myVariable)side</span>
您可以使用 <span>I want to write in@(myVariable)side</span>
Edit: Aww.. should have known better than to answer this question ^^
编辑:哇..应该比回答这个问题更清楚^^
回答by Marc
Do it this way
这样做
<span>I want to write in@{ @myVariable }side</span>

