Question

I have a simple table

@using (Html.BeginForm("Save", "Subscription", FormMethod.Post))
{
    <table>
        <tr>
            <th>
                Name
            </th>
            <th>
                Report
            </th>            
        </tr>

        @foreach (var item in Model.ReportSubscriptions)
        {
            <tr>
                <td>
                    @Html.HiddenFor(item.Id)
                    @Html.TextBoxFor(item.Name)                    
                </td>
                <td>
                    @Html.TextBoxFor(item.Report)
                </td>
            </tr>
        }
    </table>
    <button type="submit">Save</button>
}

The save action

public ViewResult Save(IEnumerable<ReportSubscription> list)
{
    throw new NotImplementedException();
}
}

How can I get MVC to deserialize the post back to my model?

Was it helpful?

Solution

For collections you need to do a Editor template and use

@Html.EditorFor(m => m.Collection);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top