views:

258

answers:

1

problem: On first full page request, my controller invokes an applicationServices Layer (Web Service Proxy to my business tier) in order to populate a collection of current services that is stored in my own controller base class property. This is then to be displayed within a view. Everything within the context of that controller has access to this "Services Collection". Now when i make further calls to the same action method via an AJAX Call, i obviously hitt a different instance of that controller meaning my services collection is empty.

So other than re-getting the whole collection again, where would i store this collection so it gets persisted between ajax requests? Should i persist it as a seperate DomainModel Object, Session object?....as ViewData is not working for me obv. Excuse my MVC ignorance :)

Any help would be greatly appreciated :)

A: 

The web is essentially stateless and MVC helps you to go down to the metal, that is, MVC does not try to make something stateful that isn't, which is mostly the path of ye olde ASP: Each request is a request of it's own and it shouldn't know anything about any other request that has been performed in the past.

I feel it is easiest to go down exactly that route, because it it tends to stay clean, fast and helps you in adhering to best practices such as separation of concerns.

AJAX takes this a step further: The idea of AJAX is that a simple 'delete' operation can be implemented as such, i.e. you only need to authorize and perform one very small query on the persistence layer. That's it. You don't even need to pass a modified page back to the user. A simple machine-readable success/error indication via JSON is sufficient.

If you start to pull lots of services around for small AJAX requests, you really lose most of what it's good for.

I'd also suggest you don't store a bunch of services in a base controller. Chances are that for most requests, you will only need a small subset of these. It's best practices to retrieve only those service you absolutely positively need.

mnemosyn
Thankyou.I have a services View,which contains a jqueryUI tabs plugin. On the first Tab i pull back a full Services List,as well as pulling back the full list,i then filter this list into 4 seperate collection categories depending on certain flags:1)can be monitored 2)needs renewal 3)is a backup service etc.Then when each of tabs are selected i pull out their relevant collections for their tab.With your response in mind,are u saying i should initially do this filtering at the stored procedure level, and then just hit the db on every subsequent request albeit for each tabor each JqGrid request?
Podders
I don't really understand what you mean. This has nothing to do with stored procedures.The tabs themselves are based on some list of services? Then you should pull that list in the corresponding action on request.Now the actual tabs contents can be loaded using AJAX: They don't need to pull anything but their very own information, and they will be served by a different action on your controller. Then the tabs' contents are up-to-date on request. That minimizes server load (unless you know users will always use all tabs), but users will have a (slight) delay.
mnemosyn
Soz for the confusion, as i appreciate your help greatly!Right ok,well the tabs themseleves will be hard coded on the index view as each tab will always be used(Monitor|backup|Renewal|Full etc),The contents of each tab will be a subset of the full services collection (that i got on the 1st Full Page request of site).As i HAVE to filter the entire service list in one of the controllers in order to split the list into diff categories(ILists). Then each individual list populates a partial view that is returned via an AJAX get to each of their relevant tabs contents.
Podders
So you need to get some `ILists` in order to populate the partial views, but you want to only fetch the Services-Thingie once for performance reasons?
mnemosyn
yes this is correct, so i populate a List<ServiceHeaderInfo> on 1st full req, filter them on certain properties, store these as individual collections.Then each tab will request its relevant collection via an ajax req. I realise im obviously breaking some serious MVC rules here. Could i just persist each subset collection in SEssion?...as hitting the Db for each of the tabs contents is not an option
Podders