ASP.NET MVC supports multiple type of Result responses to an Action. It can be a View, a File, a Content, a JavaScript, a Json object or even a custom result. For most of the cases where you want o support AJAX calls, you may choose to use JsonResult. While creating it is quite straightforward, one of the common mistakes that I found was around the usage of JsonRequestBehavior value. If you use the default implementation of Json method present in Controller class then you way notice few overloads of the method.
AllowGet and DenyGet values specify if the JsonResult response should be allowed or denied in an Action that is exposed over HTTP GET method. If you do not specify the value i.e. use an overload of Json method that does not take this parameter, the internal implementation uses DenyGet which means the Action method will return Http Status 500 in case it is exposed over HttpGet. This is, in my opinion, a good thing because you need to be cautious about what you expose as a GET operation.
You would surmised by now that these kind of restrictions do not allow on HTTP POST operations :).
No comments:
Post a Comment