Using Inline C# inside Javascript File in MVC Framework

后端 未结 9 1716
野性不改
野性不改 2020-12-31 07:39

I am trying to get inline C# to work in my JavaScript files using the MVC Framework. I made this little test code up.

$(document).ready(function() {
    ale         


        
相关标签:
9条回答
  • 2020-12-31 08:22

    Your web server does not process .js files, it only serves them to the client. This is in contrast to .aspx or other ASP.NET file types. These files are interpreted by your server before they are served up to the client.

    0 讨论(0)
  • 2020-12-31 08:25

    That inline C# has to be processed by the server in order to make sense. Naturally, it won't work with a just-plain-JavaScript file.

    0 讨论(0)
  • 2020-12-31 08:26

    when you have C# code in a separate file and include it in your View the Server does not process the code, the script file will be called by the browser and the inline script would be treated as plain string

    alternatively you can try script runat=server when including you script file but I am not sure about the effects of this

    0 讨论(0)
提交回复
热议问题