I came across a situation in which I needed the MVC Webgrid on my page, but only after I retrieved the criteria to do a search. Having a LIST in my model for the data to populate the grid, if I put the webgrid in the View, when the View loaded, it threw an error because the LIST was null.

In the end, there was a simple fix. All I had to do was check first to see if the data was null with an if block:


        @{
    var grid = new WebGrid(Model.Users,
        canSort: false);
        }
and then:
   @if (Model.Users != null)
            {
                @grid.GetHtml(//finish grid here)
            }