开发者

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

Hi When migra开发者_高级运维ting 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


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).


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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜