Separating JavaScript in cshtml razor views

前端 未结 6 1877
半阙折子戏
半阙折子戏 2021-01-02 17:46

I\'m new to ASP.NET/MVC3 and I\'m trying to figure out how to separate my JavaScript (which contains C#) from the rest of the HTML.

If I put them into .JS files and

6条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 18:01

    Instead, do something like this in your view page:

    var options = {
        parameter1 : '@(SomeC#Value)',
        parameter2 : '@(SomeC#Value)',
        parameter3 : '@(SomeC#Value)',
    }
    

    then call something like:

    myJavascriptObject.init(options);
    

    and have the Javascript use the passed-in options to control flow, etc.

提交回复
热议问题