I’m developing an ASP.Net mvc application which has a requirement to do some small, atomic actions without an entire page postback. The logical way of doing this is of course with an ajax call.
My question is – What would people suggest is the best way of achieving this?
As far as I am aware I can do it along the following lines:
- WCF + ajax
- Controller actions within the mvc application – Possibly returning as JSON result.
- Webservices (seperate/combined project) + ajax
I have a requirement that the user be logged on when using the webservice/wcf/ajax, which is currently done via cookie/session id but as far as I am aware all the above methods allow this.
On the whole whichever method I end up using will be accessing the database via standardised accessible method calls, so I’m not tied into keeping everything within the same project/namespace.
Would love to hear peoples thoughts / experiences on this!
I would recommend doing it as controller actions. Here’s why: You may end up being able to make the same action return several different representations. For example, a GetPerson() action could be able to return Person data as XML, JSON, or HTML (and possibly other representations).
This is a common approach in Rails and also in ASPMVC.