I have a .js
file and would like to use the syntax of Razor
inside it.
Home
I tried to use @
but it did not work.
Home
Is there any possibility? Can someone help me? I've researched a lot, but I can not find anything ...
I have a .js
file and would like to use the syntax of Razor
inside it.
Home
I tried to use @
but it did not work.
Home
Is there any possibility? Can someone help me? I've researched a lot, but I can not find anything ...
You have the bad side, you have to do this right on the page, but it solves the problem.
Example:
Imagine your .js is something like:
var MeuObjetoJs = function(minhasVariaveis){
//Faz o que tem que fazer...
}
On your razor page, after you load the .js script you put:
<script>
var minhasVariaveis = {
minhaVariavelUm: '@Model.MinhaVariavelUm',
minhaVariavelDois: '@Model.MinhaVariavelDois'
}
var meuObjetoJs = new MeuObjetoJs(minhasVariaveis);
</script>
Alas in your .js, you would normally access with:
minhasVariaveis.MinhaVariavelUm
minhasVariaveis.MinhaVariavelDois
And so on ...