I'm trying to pass a list of items that have their checkbox checked. The problem is that when I press submit, my controller does not receive anything from the view ( my items of type IEnumerable are null )
Here is my view :
@model IEnumerable<MyApp.Models.MyClass>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
</head>
<body>
<div>
@using (Html.BeginForm())
{
foreach(var item in Model)
{
Html.CheckBoxFor(modelItem => item.Checked);
Html.DisplayFor(modelItem => item.Url);
<br/>
}
<input type="submit" value="Submit" />
}
</div>
</body>
</html>
This my model :
namespace MyApp.Models
{
public class MyClass
{
public string Url;
public bool Checked;
public MyClass(string item)
{
Url = item;
}
public MyClass()
{
}
}
}
And this is my controller :
[HttpPost]
public ActionResult Something(IEnumerable<MyClass> items)
{
//bla bla bla
}