Raouf
Raouf

Reputation: 41

JqGrid doesn't work in ASP.NET MVC2

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?

Upvotes: 3

Views: 2006

Answers (3)

Raouf
Raouf

Reputation: 41

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.

Upvotes: 1

Sruly
Sruly

Reputation: 10540

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

Upvotes: 2

Pharabus
Pharabus

Reputation: 6062

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

Upvotes: 0

Related Questions