Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor syntax in separate js file

I have a script file, script.js that holds all the javascript for a given page. In there, I do some ajax POST methods and generate an HTML view from the response. There are certain buttons that I want to be shown if the current user is an admin / hidden if the current user is not an admin.

How can I add Razor syntax in success: function () {}; to display / hide those buttons?

like image 468
rabid_zombie Avatar asked Jan 23 '12 23:01

rabid_zombie


2 Answers

You're looking​​ for RazorJS.

like image 61
SLaks Avatar answered Oct 22 '22 16:10

SLaks


Just wanted to add to SLaks' answer a few more details that made it hard for me to use RazorJS.

After installing it with the Package Manager as explained here, you should add in your razor view the following line:

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

And then all your razor code will work just fine!

like image 31
Soph Avatar answered Oct 22 '22 14:10

Soph