试图改进我的编码风格我尝试了不同的解决方案,但我无法弄清楚什么是最好的.
我已经开始将JavaScript放在我的视图中,但我并不特别喜欢这个解决方案.
使用Visual Studio进行调试很困难,而且它会"污染"页面.
我的新"趋势"是将页面的脚本放在单独的文件中.
我面临的唯一问题是代码.
为了解决这个问题,我已经定义了这样的JavaScript变量:
<script type="text/javascript">
var PriceListFetchAction = '<%=Url.Action("Fetch", "PriceList")%>';
var UploaderAction = '<%=Url.Action("UploadExcelPriceList", "PriceList")%>';
var ModelId = '<%=Model.id%>';
var ImportType = '<%=Model.Type%>';
var customerCodeFetchAction = '<%=Url.Action("FetchByCustomerCode", "Customers")%>';
var customerNameFetchAction = '<%=Url.Action("FetchByCustomerName", "Customers")%>';
var ImportErpAction = '<%=Url.Action("ImportPriceListErp", "PriceList")%>';
var imageCalendar = '<%=Url.Content("~/Content/Images/calendar.png")%>';
</script>
Run Code Online (Sandbox Code Playgroud)
然后我在我的JavaScript文件中使用变量.在性能,调试和风格方面最好的是什么?
我正在使用jQuery Lightbox作为我的图片库.
按钮图像的
URL是' '
如果我的URL是../../Content/Lightbox/lightbox-btn-next.gif'
那么工作正常localhost/Something1/Somtehing2'
如果我使用其他路线' localhost/Something1/Something2/Something3''那么URL按钮图像是不正确的.
我可以使用Url.Action()里面的.js文件吗?
这就是我调用.js文件的方式:
<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery.lightbox-0.5.js") %>"></script>
Run Code Online (Sandbox Code Playgroud)