Share via


Razor code in js files.

Question

Friday, February 7, 2014 6:25 AM

Hi all! How can I use Razor code inside javascript file (*.js). I've tried to use RazorJS(http://john.katsiotis.com/blog/razorjswrite-razor-inside-your-javascript-files) but it returns an error "MarkupParser couldn't be loaded from System.Web.Razor assembly". I guess it's because RazorJS didn't update too long and it become deprecated. Do you know any other solutions?

All replies (3)

Friday, February 7, 2014 6:52 PM ✅Answered

You could take a look at the technique described here:

http://blog.mariusschulz.com/2013/07/07/generating-external-javascript-files-using-partial-razor-views


Tuesday, February 11, 2014 11:53 PM ✅Answered

Hi DavyJohnes,

Thanks for your post.

I found a razor engine RazorJS

on nuget that solves@ in js files

The owner blog and explanations about the package abilities

The Nuget package 

More information:

asp.net-mvc: razor '@' symbol in js file

How to embed Razor C# code in a .js file?

Hope this helps you.

Best Regards,

Eileen


Friday, February 7, 2014 7:06 AM

How can I use Razor code inside javascript file (*.js).

Why do you need that ? It is simpler to pass javascript var from .cshtml to the js