Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
155
GridDataSourceActionAttribute throwing error OnActionExecuted
posted

Hi,

I  Want to know what exactly OnActionExecuted action of GridDataSourceActionAttribute  does?

we were using model class to bind data to view in our project as below

In Controller:

System.Type modelType = Type.GetType("System.Collections.Generic.List`1[" + modelClass + "]")

// here model class is public class which has all properties which we want to display in gri.d.

string json = Newtonsoft.Json.JsonConvert.SerializeObject(dataTable);
var model = Newtonsoft.Json.JsonConvert.DeserializeObject(json, modelType);

return ((IList)model).AsQueryable();

after controller action gets executed the below code is getting called.

public void OnActionExecuted(ActionExecutedContext filterContext)
{
var viewResult = filterContext.Result as ViewResult;
GridDataSourceActionAttribute igAttribute = new GridDataSourceActionAttribute();
igAttribute.OnActionExecuted(filterContext);
}

This was working fine for us when we perform sorting and grouping with the above code.

Now we are removing the model class and binding data directly to grid as below

In Controller:

string json = Newtonsoft.Json.JsonConvert.SerializeObject(dataTable);
var model = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(json)

return ((IList)model).AsQueryable();

public void OnActionExecuted(ActionExecutedContext filterContext)
{
var viewResult = filterContext.Result as ViewResult;
GridDataSourceActionAttribute igAttribute = new GridDataSourceActionAttribute();
igAttribute.OnActionExecuted(filterContext);
}

with this code changes sorting and grouping is not working for me. gettinng argumentnullexception (value cannot be null).

i cannot debug the method also for more information.

Can anyone help me to figure out why this issue is happening?

Thanks,

Shwetha

Parents
No Data
Reply
  • 485
    Offline posted

    Hello Swetha,

     

    Thank you for posting in our forum.

     

    The GridDataSourceActionAttribute class extends the MVC FilterAttrubite. The idea of this filter is to transform the ActionResult into a JsonResult instance, taking into account all Request parameters such as paging, sorting, and filtering.

    The problem might be occurring because the JSON doesn’t get deserialized properly. OnActionExecuted tries to type cast the Model as a DataTable, DataSet or IQueryable using the “as” keyword. When it fails, instead of throwing an error, it returns null. That might be the reason you are getting the ArgumentNullException.

    Could you please provide some clarification on why you have changed the line:

    var model = Newtonsoft.Json.JsonConvert.DeserializeObject(json, modelType);

    to this:

    var model = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(json) ?

    This might give me a clue about what is causing the issue and give you a more concise answer.

     

    If you need any additional assistance, feel free to contact me.

     

     

    Best Regards,

    Vasil Pavlov

    Associate Software Developer

    Infragistics, Inc.

Children