[RESOLVED]Model Bind a Lists not working

Using MVC5 the model binding for checkboxes no longer works. :(

Plain HTML

<form>
<input type="radio" value="Food" name="Category" />
<input type="radio" value="Sports" name="Category" />

<input type="checkbox" value="1" name="ProductName" />
<input type="checkbox" value="2" name="ProductName" />
<input type="checkbox" value="3" name="ProductName" />
...
</form>

Controller

public class HomeController: Controller
{
...
[HttpPost]
public ActionResult Index(ProductCategory productCategory, ICollection<ProductLists> products) {

return View(products); //<<----products is null :-( 
}
}

Models

public class ProductLists
{
public int ProID { get; set; }
public string ProductName { get; set; }
}

public class ProductCategory
{
public int CatID { get; set; }
public string Category { get; set; }
}

Thank You, imperialx

hands down the best resource for list binding.

http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/

Check out fiddler to see what your webform request is. If thats of no use, dig in deeper with model binding to find out why your serialization is not working.

Leave a Reply