问题描述
有人可以格式化低于code,这样我可以用剃刀设置使用C#code srcript变量?
Can someone format the code below so that I can set srcript variables with c# code using razor?
以下不工作,我有这样的说法,以方便人来帮助。
The below does not work, i've got it that way to make is easy for someone to help.
@{int proID = 123; int nonProID = 456;}
<script type="text/javascript">
@{
<text>
var nonID =@nonProID;
var proID= @proID;
window.nonID = @nonProID;
window.proID=@proID;
</text>
}
</script>
我得到一个设计时间误差
I am getting a design time error
推荐答案
您应该看一看,你的剃刀页面的输出结果。其实,你需要知道什么是执行服务器端
和客户端
。试试这个:
You should take a look at the output that your razor page is resulting. Actually, you need to know what is executed by server-side
and client-side
. Try this:
@{
int proID = 123;
int nonProID = 456;
}
<script>
var nonID = @nonProID;
var proID = @proID;
window.nonID = @nonProID;
window.proID = @proID;
</script>
输出应该是这样的:
The output should be like this:
根据的是什么版本您正在使用的Visual Studio,这一点在设计时的一些要点与剃刀意见。
Depending what version of Visual Studio you are using, it point some highlights in the design-time for views with razor.
这篇关于如何设置使用MVC4剃刀的JavaScript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!