Reputation: 4332
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.
Here is some sample code -
@(x.FormPanel()
.ID("MyDetailsPanel")
.Title("My Details")
.Frame(true)
.Height(525)
.Width(425)
.Margin(5)
.Items(
x.TextFieldFor(m => 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)
)
......
Here is the model -
public class MyDetailsViewModel
{
public int Id { get; set; }
public string Title { get; set; }
public List<SomeDto> MyList { get; set; }
}
and here is the controller -
public ActionResult MyDetailsPartial(string id)
{
var vm = new MyDetailsViewModel();
vm.MyList = new List<SomeDto>();
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;
}
I can't understand why I can't pass a custom list from the model into the datasource for the gridpanel.
Any thoughts would be great.
Upvotes: 0
Views: 1286
Reputation: 4332
I was able to get this working by using GridPanelFor. By using this, the view renders and updates as expected.
Thanks
Upvotes: 1