Avi
Avi

Reputation: 1964

.net mvc design ajax calls (Where to put ajax methods)

Hi When migrating from ASP.NET to MVC ASP.NET it looks like the MVC is more AJAX friendly. but still I run into design issue, Does someone knows Microsoft intention about the design when calling AJAX methods? Where do I need to put this methods by default, in a separate controller, the same controller? Is there any kind of official info about it?

Thanks

Upvotes: 1

Views: 140

Answers (3)

Alvis
Alvis

Reputation: 3743

I would suggest taking SessionState into consideration when making the choice of method placement.

For instance, I would move ajax actions into a separate controller if I am using session state in regular actions, but not in ajax actions (which makes sense for me) and I would like the ajax methods to execute asynchronously. Then I put those ajax methods in a separate controller and mark the controller as [SessionState(SessionStateBehavior.Disabled)] (or ReadOnly). I have found this to be a great improvement in terms of performance.

Note, that you use Session when you use TempData, ViewData or ViewBag variables.

SessionState is explained here: ASP.NET MVC and Ajax, concurrent requests?

Upvotes: 0

Carls Jr.
Carls Jr.

Reputation: 3078

You might wanna try on having a review on some asp.net samples here. This will give you some ideas. :)

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038850

I don't think that there is any official best practices. Personally I like to follow RESTful conventions when organizing cotrollers and actions no matter how those actions are consumed (AJAX or not).

Upvotes: 1

Related Questions