怎么处理JS文件里服务器端标签的最佳方式? [英] What the best way to handle server side tags inside of a js file?

查看:115
本文介绍了怎么处理JS文件里服务器端标签的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Asp.NET MVC和在整个我的整个应用程序jQuery的一个巨大的依赖(如果不知道这是这里重要与否)。我试图建立一套JS库文件的旁边我的看法去。那我面对的问题是,我需要一种方法来管理我的文件和行动链接服务器端的位置,我的所有影像地图和Ajax调用。

I'm using Asp.NET MVC and have a huge dependency on JQuery throughout my entire application (not sure if that's important here or not). I'm trying to build a set of js library files to go along side my views. The problem that I'm faced with is that I need a way to manage the server side location of my files and action links for all of my image maps and ajax calls.

目前,我坚持把所有各aspx页面里面我的脚本code,这样我可以使用服务器端脚本标签是这样的:

For now, I'm stuck putting all of my scripting code inside each aspx pages so that I can use the server side scripting tags like this:

    $("#StartDate").datepicker({
        changeMonth: true,
        changeYear: true,
        showOn: 'button',
        buttonImage: '<%= Url.Content("~/Content") %>/Images/calendar.png',
        buttonImageOnly: true
    });

    function fillDates(periodType, periodOffset)
    {
      $.ajax({
        url: '<%= Url.Action("GetDates", "Tracking") %>',
        dataType: "json",
        data: {"pt": periodType, "po": periodOffset},
        success: function(result){
            if (result.Status == "Success")
            {
                $("#StartDate").val(result.StartDate);
                $("#EndDate").val(result.EndDate);
            }
            else
            {
                alert(result.Status + ": " + result.Message);
            }
        }
      });        
    }

我想这code移动到一个js文件。我将如何做到这一点,仍然能够映射到我的应用程序的根目录。

I'd like to move this code to a js file. How would I do this and still be able to map to the root directory of my application.

推荐答案

虽然我从来没有尝试过,你可以文件映射的.js到ASP.NET处理程序和处理他们,他们供应的时候。你如何做到这一点映射取决于IIS的版本,你可能会使用一个HttpModule做处理。

Though I've never tried it, you could map .js files to the ASP.NET handler and process them when they are served. How you do that mapping depends on the version of IIS and you'd probably use an HTTPModule to do the processing.

这篇关于怎么处理JS文件里服务器端标签的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆