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

后端 未结 6 1716
深忆病人
深忆病人 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条回答
  •  悲&欢浪女
    2020-12-07 11:48

    Personally I always put javascript in separate files. Global variables which depend on routing or some server side information inside the view. Exactly as you do. As an alternative to storing global variables you could use anchor or form elements which already contain the url and then ajaxify them. As far as model values are concerned they could be stored also in DOM elements such as hidden fields, CSS classes, HTML5 data-* attributes, ... but this might not be applicable to all situations.

提交回复
热议问题