I have a problem sending a list of objects to my controller. For some reason I keep getting a list with count=0.
This is the model I send :
public class DIYViewModel
{
public List<Item> Items { get; set; }
public List<CheckModel> Checklist { get; set; }
public int Page { get; set; }
public int TotalPages { get; set; }
public DIYViewModel(int page, List<Item> items,List<CheckModel> checklist)
{
int index = (page - 1) * 10;
this.Items = items.Skip(index).Take(10).ToList();
this.Page = page;
this.TotalPages = ((items.Count - 1) / 10) + 1;
this.Checklist = checklist;
}
}
This is the CheckModel :
public class CheckModel
{
public int Id
{
get;
set;
}
public string Name
{
get;
set;
}
public bool Checked
{
get;
set;
}
}
This is the View that gets a DIYViewModel:
@model Homeserve.Web.Models.DIYViewModel
@using Sitecore.Data.Items
@using Homeserve.Web.Models.Helpers
@using (Html.BeginForm("Testing", "DIY", new { app=Model.Checklist }))
{
foreach (CheckModel item in Model.Checklist)
{
@Html.HiddenFor(it => item.Id)
@Html.DisplayFor(it => item.Name)
@Html.CheckBoxFor(it => item.Checked)
}
<input id="Submit1" type="submit" value="submit" />
}
@{
foreach (Item newsItem in Model.Items)
{
<p> @Html.Sitecore().Field("Article Title", newsItem)</p>
<p> @Html.Sitecore().Field("Article Date", newsItem)</p>
<p> @Html.Sitecore().Field("Contents", newsItem)</p>
<p> @Html.Sitecore().Field("Article Image", newsItem)</p>
<p>social media stuff here</p>
}
}
@Html.DIYsPagination(Model.Page, Model.TotalPages)
My controller:
[HttpPost]
public ActionResult Testing(List<CheckModel> app)
{
return View();
}
List app is always a list with 0 items even though in the view all is working perfectly.