If you got a couple of linqTOsql objects that I am trying to edit through a form.
Firstly, there is a class Stream:
[Table]
public class Stream
{
[HiddenInput(DisplayValue = false)]
[Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
public long StreamID { get; set; }
private EntitySet<Stream2FieldTypes> _Stream2FieldTypes;
[System.Data.Linq.Mapping.Association(Storage = "_Stream2FieldTypes", OtherKey = "StreamID")]
public EntitySet<Stream2FieldTypes> Stream2FieldTypes
{
get { return this._Stream2FieldTypes; }
set { this._Stream2FieldTypes.Assign(value); }
}
}
Then there is a class Stream2FieldTypes:
[Table]
public class Stream2FieldTypes
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
public long s2fID { get; set; }
[Column]
public long StreamID { get; set; }
private EntitySet<Stream> _Stream;
[Association(Storage = "_Stream", ThisKey = "StreamID")]
public EntitySet<Stream> Stream
{
get { return this._Stream; }
set { this._Stream.Assign(value); }
}
}
I am using the linqTOsql repository to get these objects and send them to the view as follows:
public ActionResult StreamEdit(long id)
{
Genesis.Domain.Entities.Stream stream = genesisRepository.Streams.FirstOrDefault(x => x.StreamID == id);
return View(stream);
}
All are sent for viewing without problems ... But when the form on the view is submitted, for some reason it is lost Stream.Stream2FieldTypes. I will catch a form submission with this action:
[HttpPost]
public ActionResult StreamEdit( long id, Genesis.Domain.Entities.Stream form)
{
return View(form);
}
And a view without a collection Stream2FieldTypes.
The view writes the Stream2FieldTypes types as follows:
<% for (int i = 0; i < (Model.Stream2FieldTypes != null ? Model.Stream2FieldTypes.Count() : 0); i++) %>
<% { %>
<div class="ListItem">
Label: <%: Html.EditorFor(x => x.Stream2FieldTypes[i].s2fLabel, new { style="width:100px" })%>
Required: <%: Html.EditorFor(x => x.Stream2FieldTypes[i].s2fIsRequired)%>
Field Type ID": <%: Html.EditorFor(x => x.Stream2FieldTypes[i].FieldTypeID, new { style="width:20px;" })%>
Stream ID: <%: Html.EditorFor(x => x.Stream2FieldTypes[i].StreamID) %>
</div>
<% } %>
Why does mvc default model binding correctly bind a nested collection?