views:

823

answers:

5

What is the best way to manage the JavaScript files and the functions/objects context in an ASP.NET MVC app?

A: 

I put all my js files in the Content/Js folder. Then add URL helpers that allow me to change this in the future. My code isn't online, but I stole the idea from Rob Conery MVC Commerce demo.

Not sure what you mean by "manage...the functions/objects context in ASp.NET MVC app"

I think you're asking how to segment/partition your scripts. You should separate your JS files into separate chunks of functionality.

CVertex
A: 

i'm thinking about a main js file that is responsible for all the calls of js function like:

mainApp = function(){

return{

init:function(){

},

function1:function(){

}

};

};

nut in a way of it fits an mvc app.

Moran
+5  A: 

Google says http://javascriptmvc.com/

Midhat
+1  A: 

If you're looking for something like that, you should definitely check out MooTools as they implement classes almost exactly the way you describe. Overall, I've found their approach to be very clean, extensible, and maintainable. For example, here is a class template I use to write all of my classes (note that it uses some MooTools-specific syntax):

var className = new Class ({

    Implements: [Events, Options],

    options: {
     option1: 'option1',
     option2: 'option2'
    },

    initialize: function(options){
     this.setOptions(options);
    },

    function1: function(){

    },

    function2: function(){

    }
});
VirtuosiMedia
A: 

yes , but this is not a MooTools unique technique,

this is called Object literal pattern.

i'm looking for a way to manage my ajax app according to the current state od the asp.net mvc

Moran