do you write your JavaScript in a ASP.NET MVC view … or in a separate JavaScript file?

后端 未结 6 1705
深忆病人
深忆病人 2020-12-07 11:24

Trying to improve my coding styles I\'ve tried different solutions but I can\'t figure out what is the best.
I\'ve started putting JavaScript inside my views but I don\'

6条回答
  •  -上瘾入骨i
    2020-12-07 11:49

    vandalo,

    I've borrowed a situation whereby the javascript is all in seperate file. however, using a custom action result on the controller, the js is invoked as an htmlhelper function and has a context with the page. the htmlhelper actually serves the code as a file and it's therefore cached, thus speeding up excecution/delivery.

    I know you'll be curious to see how this works, so will update the answer to show the mechanics of this a little later.

    til then... (here's a link to where i got my inspiration. i then tweaked this to my own needs)

    ASP.NET MVC routing and paths is js files

    ok, here's my worked example (a simple mvc 2 project that contains required helpers and classes) - enjoy:

    http://www.gatehousemusic.com/downloads/ServeJsExample.zip

提交回复
热议问题