1
I have an Action Usuario
that displays user details among other actions that can be performed. I also have a code javascript
that needs in some part to set a model property in the javascript variable. Follow the code below:
@model Aprendendo.Asp.Net.Model.Usuario
//Códigos html
<script type="text/javascript">
var idUsuario = @Model.Id;
//Demais códigos
</script>
But this way is not working. What to do in this situation?
But this does not work when the Javascript code is in a file external to the view, because Javascript does not recognize the Razor syntax.
– Ulysses Alves
That’s right Ulysses, in this case it would be better to use your solution presented below
– João Alex
Yeah, @John Alex. But in cases similar to the question, where the Javascript code is declared in a Script within a View, your solution fits perfectly as well.
– Ulysses Alves