Skip to content Skip to sidebar Skip to footer

What The Best Way To Handle Server Side Tags Inside Of A Js File?

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 file

Solution 1:

You can put the base url in your view, and reference it from your js files

// site.mastervar appPath = <%=ResolveUrl("~/")%>;

// *.jsfunction dosomething()
{ 
    var src = appPath + "content/images/test.png";
    var action = appPath + "controller/action";
}

Note: this method requires that you write your action urls manually instead of calling Url.Action().

Solution 2:

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.

Post a Comment for "What The Best Way To Handle Server Side Tags Inside Of A Js File?"