I apologize for my very poor terminology,
but I'll try to explain myself better:
give a model that contains a list of obj and an obj
I want a form in my view to send the obj (and the list )to the controller
the controller to add the obj to the updated list and send it back to the view.
my problem is passing the "initial" list to the form on submit;
this doesn't work:
<div class="form-group">
@Html.HiddenFor(m => m.RequestList, Model.RequestList)
</div>
Edit: answering to...
This question may already have an answer here:
Model Model Binding to a List MVC 4 3 answers
no it isn't, I'm not trying to edit the list rather than just "declare it", anyway as suggested I'm trying to loop the elements in the list and "add it to the new one";
something get actually passed to the model, but is null!
for (int i = 0; i < Model.RequestList.Count(); ++i) { @Html.HiddenFor(m => m.RequestList[i], new { StartTime = Model.RequestList[i].StartTime, EndTime = Model.RequestList[i].EndTime, StatusId = Model.RequestList[i].StatusId, }) }
again: what am I doing wrong?
- I think this solution is actually closer to what I mean (sorry isn't stackoverflow)
but trying something like this
@using (Html.BeginForm("CreateComplex", null, FormMethod.Post, new { @class = "", RequestList = Model.RequestList}))
still doesn't work