views:

944

answers:

3

I have a project in ASP.NET MVC1 using VB.NET controlers and JqGrid. it works fine under MVC1. After migrating the project to ASP.NET MVC2, the grid is no longer populated. It seems that there is some new restrictions on returned Jsonresult in MVC2. How to solve this in VB.NET. Controler function populating the jqgrid is something like this :

Function GetGridRecordset(ByVal qry As String) As JsonResult
  Dim result = New JsonResult()
  ...
  ...
  Return result
End Function

Is there anyone who have a solution?

A: 

I would need to see more code but could this be down to the changes in JsonResult in MVC 2? you may need to allow the GET verb by setting the JsonRequestBehavior Property to JsonRequestBehavior.AllowGet

Pharabus
The code works perfectly under MVC1. It seems that the question is:Is there another way to enable the AllowGet property for the JsonRequestBehavior in VB.Net than this one: return Json(data, JsonRequestBehavior.AllowGet)? thank you!...
Raouf
+2  A: 

In Asp.net MVC 2 JsonResult only responds to http Post.

http://www.asp.net/learn/whitepapers/what-is-new-in-aspnet-mvc/#_TOC5

here is a post about why Get is not supported for Json

http://haacked.com/archive/2009/04/02/anatomy-of-csrf-attack.aspx

Sruly
+1  A: 

In MVC2 : Dim result = New JsonResult() make by default result.JsonRequestBehavior = JsonRequestBehavior.DenyGet while this was not the case in MVC1. The response is :

Function GetGridRecordset(ByVal qry As String) As JsonResult 
  Dim result = New JsonResult()
  ...
  ...
  result.JsonRequestBehavior = JsonRequestBehavior.AllowGet
  Return result    
End Function

Now, jqGrid works fine under MVC2 without modifying anything on the client side code.

Raouf