How to get visual studio to recognize cshtml file as javascript

I am writing a css / js page that has dynamic parts. To do this, I use the cshtml file containing css / js - I use mvc.net and return css from the controller action.

The problem is that the visual studio recognizes this page as html and not as javascript / css, so it does not give me javascript / css coloring and IntelliSense.

My questions:

  • there is a better / easier way to create dynamic css / js in .net
  • How can I get a visual studio to recognize a cshtml page as javascript.
+5
source share
4 answers

I know this is an old post ... but ...

, , script javascript .cshtml. (JavascriptController.cs), , script. OnActionExecuting.

this.Response.Filter = new ScriptFilter(Response.Filter, Response.ContentEncoding);

, , RazorJS, js, MVC. script .

,

/Javascript/{}

javascript , script, script.

<script src="http://{host}/Javascript/{action}"></script>
+1

- javascript javascript .js, css .css cshtml <script> <link>.

.

<script src="Scripts/scriptName.js" type="text/javascript"></script>
<link rel="stylesheet" href="Content/styleSheetname.css" type="text/css" />

, ()// .

0

<script> <style> js/css , , , , . - :

<script>
 function myFunction_@MyFunc(params)(obj) {  return obj.field + @MyOtherFunc(params); }
<script>

@MyFunc (params) @MyOtherFunc (params) ​​

0

JavaScript RazorJS nuget. .

Still trying to find a better way to do this with Controller / Views and still be able to use intellisense and get decent coloring.

0
source

All Articles