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.
JavaScript
x
16
16
1
@{int proID = 123; int nonProID = 456;}
2
3
<script type="text/javascript">
4
@{
5
6
<text>
7
8
var nonID =@nonProID;
9
var proID= @proID;
10
window.nonID = @nonProID;
11
window.proID=@proID;
12
13
</text>
14
}
15
</script>
16
I am getting a design time error
Advertisement
Answer
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:
JavaScript
1
14
14
1
@{
2
int proID = 123;
3
int nonProID = 456;
4
}
5
6
<script>
7
8
var nonID = @nonProID;
9
var proID = @proID;
10
window.nonID = @nonProID;
11
window.proID = @proID;
12
13
</script>
14
The output should be like this:
Depending what version of Visual Studio you are using, it point some highlights in the design-time for views with razor.