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 3344186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:02:25+00:00 2026-05-18T01:02:25+00:00

I am currently working on an update view for a model I have in

  • 0

I am currently working on an update view for a model I have in ASP.NET MVC. The model is called Document and has child Links:

[Association(ThisKey = "AssetID", OtherKey = "AssetID")]
private EntitySet<Link> links = new EntitySet<Link>();
public IQueryable<Link> Links
{
    get { return links.AsQueryable().Select(l => l); }
    set 
    {
        links.Assign(value);
    }
}

I’ve got my strongly-typed update form rendering the model correctly (including all links) through a EditorTemplate for link and then use of Html.EditorFor(model => model.links). This successfully grabs and displays all links for the given Document.

When the form is submitted and I use Fiddler to see the data that is posted back, for each link it contains all the fields like Links[0].Id = 12323, Links[0].DisplayOrder = 1, etc.

The problem though is when I put a breakpoint on the controller method that I am posting to, and examine the Document object that is being posted, its Links collection is empty. I have tried adding additional binding properties to my controller as described here, but with no luck–the argument passed to the parameter is always null.

Any ideas why my model does not contain these links when I try to update it? Thanks

  • 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-18T01:02:26+00:00Added an answer on May 18, 2026 at 1:02 am

    The reason this happens is simple: it is because you are not using view models which is what I would recommend. Let me elaborate. In your views you are directly using your data models which are not POCO objects and using Linq to SQL pollutes them even further with those EntitySet<T> stuff which are specific to your DAL and just look at the setter of the Links property: links.Assign(value);. Don’t expect from the default model binder to be that intelligent. A view should never work with things like EntitySet<T> (this is an implementation specific detail).

    So start by defining a POCO view model which expresses the intent of the view which is editing links:

    public class MyViewModel
    {
        // As you can see the sole responsibility of the view is to 
        // show a list of input fields for each link to be edited.
        // TODO: you could also have a view model for Link the same way 
        public IEnumerable<Link> { get; set; }
    }
    

    Now strongly type your view to this view model instead of the model. Also the POST action takes the view model as argument. You could use AutoMapper to perform the conversion between your model and view models.

    In fact every time I see a question on SO tagged with both asp.net-mvc and linq-to-sql (or entity framework) I know that there’s something wrong. Those two things should be completely separate and have nothing in common. You DAL should be abstracted away in a repository so that MVC never knows about the data access technology you are using.

    The normal scenario would be this:

    The controller action receives a view model as argument, validates it, maps this view model to some model and invokes some method from the repository passing the model. The repository returns another model which in turn is converted into a view model and passed to the view to be rendered (of course this is the complete scenario, there are cases where you could skip steps for simple actions).

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

Sidebar

Related Questions

I'm currently learning ASP.NET MVC and using Nhibernate. I would like to use Cascading
Working with the MVVM pattern, I have a pair of view model classes that
I am working with ASP.NET MVC2 RC and can't figure out how to get
I'm working on a WPF application and is using the Model-View-ViewModel pattern. The application
I currently working on an issue tracker for my company to help them keep
I am currently working on a project and my goal is to locate text
I'm currently working on creating a new C# project that needs to interact with
I am currently working on a project with specific requirements. A brief overview of
The system I am currently working on requires some role-based security, which is well
I'm currently working at a small web development company, we mostly do campaign sites

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.