0
I have a file .js
and would like to use the syntax of Razor
within it.
I tried to simply use the @
but it didn’t work.
Is there any possibility? Can anyone help me? I’ve done a lot of research, but I can’t find anything...
0
I have a file .js
and would like to use the syntax of Razor
within it.
I tried to simply use the @
but it didn’t work.
Is there any possibility? Can anyone help me? I’ve done a lot of research, but I can’t find anything...
1
Straight into the . js has no way, what you can do is instantiate your class in html/Razor, so you can set values in javascript and pass as class parameter for example...
There’s a downside, you have to do it right on the page, but it solves the problem.
Example:
Imagine that your . js is something like:
var MeuObjetoJs = function(minhasVariaveis){
//Faz o que tem que fazer...
}
Ai on your page, after vc load the script . js you put:
<script>
var minhasVariaveis = {
minhaVariavelUm: '@Model.MinhaVariavelUm',
minhaVariavelDois: '@Model.MinhaVariavelDois'
}
var meuObjetoJs = new MeuObjetoJs(minhasVariaveis);
</script>
Ai in your . js, you would access normally with:
minhasVariaveis.MinhaVariavelUm
minhasVariaveis.MinhaVariavelDois
And so on and so forth...
Browser other questions tagged javascript razor
You are not signed in. Login or sign up in order to post.
Have you tried using Razorjs? http://nuget.org/List/Packages/RazorJS
– Jean Gustavo Prates