I have this model:
public class MyClassVM
{
public Product MyProduct { get; set; }
public IEnumerable<Dog> MyDogs { get; set; }
}
Then I have this action in a controller:
[HttpPost]
public ActionResult MyAction(MyClassVM)
{
//do something...
}
I have an html view and have been for a while trying to bind the object and send it from the view to the controller as a parameter but I've not been able yet... Which is the correct way to do this?
<form method="post" action="MyController/MyAction">
@{ foreach (var dog in Model.MyDogs)
<tr>
<td><input type="checkbox" name="[@i].MyDogs" /></td>
</tr>
}
<input type="hidden" name="MyProduct" value="@Model.MyProduct"/>
<input type="submit" value="Submit"/>
</form>
But when it arrives to the controller is always null... I've checked the request using Dev Tools and the data is not being bound correctly. I would probably need to serialize
the object to Json
format in my view???