Basically, I would like to know if a MVC View @HTML control can handle all types of data correctly.
For instance my ViewModel is as follows:
public class ViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public MyClass Obj { get; set; } //custom class
}
Into the view, I ll strongly type the View with:
@modem <NameSpace>.ViewModel
Ideally, I would like the View to let the user fill the Name and keep records of the Id and Obj
I will end up with a form looking like this:
@using (Html.BeginForm("MyAction", "MyController"))
{
@Html.Hidden("Id", Model.Id) // --> this will work
@Html.Hidden("Obj", Model.Obj)// --> this will NOT work
@Html.TextBox("Nom", null)// --> this will work
<input type="submit" value="Submit" />
}
The Id and Name will be correctly submitted but I ll get viewModel.Obj = null into my controller:
public ActionResult MyAction(ViewModel viewModel)
So it looks that MVC can correctly handle some types and cannot some more complex types. Can someone let me know what types work and do not work?
Or did I miss something obvious??