I think there are a couple of problems with this. Essentially, you are closely linking your javascript to your page or view. I consider myself a solid .NET / C # / MVC developer, but starting with javascript, and this is exactly the type of design that I have pursued until recently. In the past, I would put all kinds of javascript into my views and make heavy use of Razor. It works in the end, but this leads to a very close relationship between your markup and the script, and ultimately creates a complex maintenance environment.
And it is better to use the built-in javascript function calls instead. The difference is subtle, but it will provide a separation of the two areas.
<script type="text/javascript"> MyFunction('@Model.myVar'); </script>
You can also enter values ββin hidden input fields, spaces, etc. through Razor and put them there on your javascript.
source share