Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1115815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:12:41+00:00 2026-05-17T03:12:41+00:00

If got a couple of linqTOsql objects that I am trying to edit through

  • 0

If got a couple of linqTOsql objects that I am trying to edit through a form.

First, there’s the Stream class:

[Table]
public class Stream
{
    [HiddenInput(DisplayValue = false)]
    [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
    public long StreamID { get; set; }

    /*other properties removes for brevity*/

    // relationship (one stream to many Stream2FieldTypes) 
    // uses EntitySet<Stream2FieldTypes> and OtherKey for the FK in Stream2FieldTypes 
    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’s the Stream2FieldTypes class:

[Table]
public class Stream2FieldTypes
{
    [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
    public long s2fID { get; set; }

    /*other properties removed for brevity*/

    [Column]
    public long StreamID { get; set; }     // FK




    // relationship (one Stream2FieldTypes to Streams) 
    private EntitySet<Stream> _Stream;
    [Association(Storage = "_Stream", ThisKey = "StreamID")]
    public EntitySet<Stream> Stream
    {
        get { return this._Stream; }
        set { this._Stream.Assign(value); }
    }
}

I use the linqTOsql repository to get these objects and send them to the view like this:

    public ActionResult StreamEdit(long id)
    {
        Genesis.Domain.Entities.Stream stream = genesisRepository.Streams.FirstOrDefault(x => x.StreamID == id);

        return View(stream);
    }

Everything get’s sent to the view without a problem… But when the form on the view is submitted, the Stream.Stream2FieldTypes gets lost for some reason. I catch the form submission with this action:

    [HttpPost]
    public ActionResult StreamEdit( long id, Genesis.Domain.Entities.Stream form)
    {

            return View(form);
    }

And the view is without the Stream2FieldTypes collection.

The view is writing the Stream2FieldTypes like this:

<% 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 isn’t the default model binder in mvc correctly binding the nested collection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:12:42+00:00Added an answer on May 17, 2026 at 3:12 am

    I would recommend you using POCO view models instead of those cluttered model classes. They are not adapted to the view and are difficult to work with. Trying to bind to LINQ specific collections like EntitySet<T> is not a good idea. This being using an editor template might actually work but even if this works bear mind that it should be a temporary solution until you introduce proper view models.

    In your main view replace the loop with this:

    <%: Html.EditorFor(x => x.Stream2FieldTypes) %>
    

    and then add a strongly typed partial view in ~/Views/Home/EditorTemplates/Stream2FieldTypes.ascx:

    <%@ Control 
        Language="C#" 
        Inherits="System.Web.Mvc.ViewUserControl<SomeNs.Stream2FieldTypes>" 
    %>
    <div class="ListItem">
        Label: 
        <%: Html.EditorFor(x => x.s2fLabel, new { style="width:100px" }) %>
    
        Required: 
        <%: Html.EditorFor(x => x.s2fIsRequired) %>
    
        Field Type ID: 
        <%: Html.EditorFor(x => x.FieldTypeID, new { style="width:20px;" })%>
    
        Stream ID: 
        <%: Html.EditorFor(x => x.StreamID) %>
    </div>
    

    Normally this should take care of generating correct input names, but to avoid people taking this as a good example: I repeat once again use proper view models.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say i got couple Objects named as txt1 and another object as lbl1.
After a site redesign, I've got a couple of pages that need to be
I've got a couple of closed shapes that I'm drawing in an iPhone app
I've got a couple of different projects that I'd like to post up as
So I've got a couple of (ginormous) KML's that I've successfully converted into 180
I just started using C# and I've got a couple of issues. Is there
I've got a couple of methods that should be executed only in the case
I've got a couple of jquery sortables inside containers that scroll vertically. When dragging
I've got a couple of Powershell scripts that automate DLL transferal and I'd like
I am using jquery and I got a couple plugins that don't offer a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.