Razor syntax in a separate js file

I have a script file, script.js that contains all the javascript for this page. There I use some ajax POST methods and generate the HTML representation from the response. There are certain buttons that I want to show if the current user is an administrator / hidden, if the current user is not an administrator.

How to add Razor syntax to success: function () {}; to show / hide these buttons?

+7
source share
2 answers

Are you looking for RazorJS .

+11
source

I just wanted to add a few more details to the SLaks answer, which made it difficult for me to use RazorJS.

After installation using the package manager, as described here , you should add the following line to your razor:

 @Html.RazorJSInclude("~/Scripts/my_javascript_file.js") 

And then all your razor code will work perfectly!

+4
source

All Articles