Skip to content
Advertisement

How to set javascript variables using MVC4 with Razor

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

I am getting a design time error

enter image description here

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

The output should be like this:

enter image description here

Depending what version of Visual Studio you are using, it point some highlights in the design-time for views with razor.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement