Articles in this section
Category / Section

How to resolve 'Value cannot be null' exception during post back

1 min read

How to resolve theValue cannot be null exception in Grid.

This exception is raised when GridAction is returned on an external AJAX Post. The cause for this exception is PagingParams is Null.

Use a condition to check whether the Post is external AJAX Post. It can be done by checking whether any of the values in PagingParams are null using the code if(args.ID == null) because for external AJAX Post PagingParams will always be null. If it is null don’t return GridAction instead return respective action result here we return Partial View so that this exception is resolved.


<div id="NavToPage">
    <input type="text" id="PageNumber" />
    <input type="button" value="Next Page" onclick="pageAction()" />
//Creating an External AJAX Post
<script type="text/javascript">
    function pageAction() {
        var pageObj = $("#PageNumber");
            type: 'POST',
            url: 'GridFeatures',
            success: function (data) {



public ActionResult GridFeatures()
     var data = new KBEditing.Models.StudentDataContext().Student.Take(100).ToList();
     ViewData["ProductName"] = "Grid";
     return View(data);
public ActionResult GridFeatures(PagingParams args, string pagenum)  //The cause of this exception is PagingParams is Null
     IEnumerable data = OrderRepository.GetAllRecords().Take(200).ToList();
     if (args.ID != null)
                  return data.GridActions<KBEditing.Models.Student>();
                  return PartialView("GridPartial", data);  //Here GridAction should not be returned.


Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment