title: ext.net mvc gridpanel using datasource with complex model type
body: <p>I am having trouble getting a partial view working. The partial view has a gridpanel embedded in it along with some other text boxes. I have a custom model class with some string properties to fill the text boxes and a list of custom objects to populate the grid. I am using .DataSource(Model.MyList) to populate the gridpanel, but I keep getting a null reference exception - object not set to an instance of an object. If I remove the datasource line, it renders correctly (obviously without any data in the grid) - the other fields are correctly populated.</p>
  
  <p>Here is some sample code - </p>
  
  <pre><code>@(x.FormPanel()
      .ID("MyDetailsPanel")
      .Title("My Details")
          .Frame(true)
          .Height(525)
          .Width(425)
          .Margin(5)        
          .Items(
              x.TextFieldFor(m =&gt; m.Title)
                  .FieldLabel("Title")
                  .AnchorHorizontal("100%"),
              x.TextField()
                  .FieldLabel("Number")
                  .AnchorHorizontal("100%"),
              x.ComboBox()
                  .FieldLabel("Type")
                  .AnchorHorizontal("100%"),
  
  
                  x.GridPanel()
                      .Title("My Grid")
                      .Frame(true)
                      .Width(400)
                      .Height(350)
                      .Store(
                          x.Store()
                              .AutoLoad(true)
                              .ID("MyStore")
                              .DataSource(Model.MyList)
                              .Model(
                                  x.Model()
                                      .Fields(
                                          x.ModelField().Name("Number").Type(ModelFieldType.String),
                                          x.ModelField().Name("Title").Type(ModelFieldType.String)
                                      )
  ......
  </code></pre>
  
  <p>Here is the model - </p>
  
  <pre><code>public class MyDetailsViewModel
      {
          public int Id { get; set; }
          public string Title { get; set; }
  
          public  List&lt;SomeDto&gt; MyList { get; set; }
      }
  </code></pre>
  
  <p>and here is the controller - </p>
  
  <pre><code>public ActionResult MyDetailsPartial(string id)
          {
              var vm = new MyDetailsViewModel();
              vm.MyList = new List&lt;SomeDto&gt;();
              if(id != null)
              {
                  vm.Title = "new title";
                  vm.MyList.Add(new SomeDto { Number = "234", Title = "abcd"});
              }            
  
              ViewData.Model = vm;
  
              var pvr = new Ext.Net.MVC.PartialViewResult
              {
                  ViewData = this.ViewData
  
              };
              return pvr;         
          }
  </code></pre>
  
  <p>I can't understand why I can't pass a custom list from the model into the datasource for the gridpanel.</p>
  
  <p>Any thoughts would be great.</p>