I have a view model and exists a list inside. When I send the data to controller by post, the list is comming null.
What's the problem?
View:
@model MyProject.ViewModel.MyViewModel
@{
var grid = new WebGrid(Model.MyList);
}
@using(Html.BeginForm())
{
@grid.GetHtml(columns: grid.Columns(grid.Column(header: "Column", format: @<text><input name="Add" type="checkbox" @(item.Checked == true ? "Checked" : null) />@item.Name</text>)))
<button type="submit">Send</button>
}
Controller:
[HttpPost]
public ActionResult MyMethod(MyViewModel viewModel)
{
// In this point, my list is comming null.
return View();
}
ViewModel:
public class ObjectModel
{
public string Name { get; set; }
public bool Checked { get; set; }
}
public class MyViewModel
{
public MyViewModel()
{
this.MyList = new List<ObjectModel>();
}
public List<ObjectModel> MyList { get; set; }
}