Replies: 7 comments
-
You need to read about Content Security Policy (CSP). Inline scripts are blocked by default as a security feature. |
Beta Was this translation helpful? Give feedback.
-
I did not know that. Thx! The reason I use inline scripts is because I can use Razor in them. Is it a good practice to use hidden fields for certain values/properties I can't access in my JS file? |
Beta Was this translation helpful? Give feedback.
-
If you need to inject some values into your JavaScript, consider creating an endpoint that returns some JSON, call that using JavaScript and do what you need. |
Beta Was this translation helpful? Give feedback.
-
Hmmm I see. And what about if I want to do ajax calls from my view. How should I get the url in my JS file? I'm used to use '@Url.Action("","")' but that does not work in this case. |
Beta Was this translation helpful? Give feedback.
-
You can hard code these in JS or stick them in the JSON I mentioned above and use |
Beta Was this translation helpful? Give feedback.
-
Do you have any example for the method you are suggesting? Thx for the help. Much appreciated. |
Beta Was this translation helpful? Give feedback.
-
https://stackoverflow.com/questions/42360139/asp-net-core-return-json-with-status-code |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am having problem running custom javascript in my _Layout file.
I made a Stackoverflow post but can't find a solution for it. (Click here)
Is this related to the template? I never had this before with any new project. Its the first time I use this.
Thx for any help!
Beta Was this translation helpful? Give feedback.
All reactions