Model is null after post
Here is my model:
public class Items
{
public string ItemName { get; set; }
public string Type { get; set; }
public bool Picked { get; set; }
}
This is my controller:
public class InvoiceController : Controller
{
[HttpGet]
public ActionResult Index()
{
using (TPGEntities context = new TPGEntities())
{
List<Items> result = (from a in context.IV00101
select new Items { ItemName =
a.ITEMDESC, Type = a.ITEMNMBR,
Picked = false }).Take(10).ToList();
return View(result);
}
}
[HttpPost]
public ActionResult Index(string searchTerm, IList<Items> model)
{
return View();
}
}
And my view:
@using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "POST",
InsertionMode = InsertionMode.Replace, UpdateTargetId = "partsList" }))
{
<input type="search" name="searchTerm" />
<input type="submit" value="OK" />
<div id="partsList">
@foreach (var item in Model)
{
<h1>@item.ItemName</h1>
<div>@item.Type</div>
<div>
@if (@item.Picked)
{
<img src="~/Images/checkbox.png" />
}
</div>
}
</div>
}
When I click the submit button, and it reaches this method:
[HttpPost]
public ActionResult Index(string searchTerm, IList<Items> model)
{
return View();
}
The model is null. I need to be able to update the properties in the
model, and then send the edited model back to the view. What am I doing
wrong?
No comments:
Post a Comment