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

  • Home
  • SEARCH
  • 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 699867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:26:01+00:00 2026-05-14T03:26:01+00:00

I want a list of different (derived) object types working with the Default Modelbinder

  • 0

I want a list of different (derived) object types working with the Default Modelbinder in Asp.net MVC 2.

I have the following ViewModel:

public class ItemFormModel
    {       
        [Required(ErrorMessage = "Required Field")] 
        public string Name { get; set; }
        public string Description { get; set; }

        [ScaffoldColumn(true)]
        //public List<Core.Object> Objects { get; set; }       
        public ArrayList Objects { get; set; }                  
    }

And the list contains objects of diffent derived types, e.g.

public class TextObject : Core.Object
    {
        public string Text { get; set; }
    }

    public class BoolObject : Core.Object
    {
        public bool Value { get; set; }
    }

It doesn’t matter if I use the List or the ArrayList implementation, everything get’s nicely scaffolded in the form, but the modelbinder doesn’t resolve the derived object type properties for me when posting back to the ActionResult.

What could be a good solution for the Viewmodel structure to get a list of different object types handled? Having an extra list for every object type (e.g. List, List etc.) seems to be not a good solution for me, since this is a lot of overhead both in building the viewmodel and mapping it back to the domain model.

Thinking about the other approach of binding all properties in a custom model binder, how can I make use the data annotations approach here (validating required attributes etc.) without a lot of overhead?

  • 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-14T03:26:02+00:00Added an answer on May 14, 2026 at 3:26 am

    Check out the Derived Type ModelBinder in MvcContrib. This allows you to modelbind to derived types through the process of ‘typestamping’ – which is handled automatically for you when using the RenderTypedPartial(…) helper. MvcContrib partials maintain binding state across partials so the Name/Id prefixes are properly maintained on a deep object graph. If you use other mechanisms like templates, then you’ll need to handle the typestamping yourself. This is explained in the documentation page.

    Getting back to your questions and how the derived types are resolved with the ModelBinder, you can register the derived type variations with attributes in a mechanism similar to the WCF KnownTypeAttribute or you can do the registration on startup. Either way, these variations are registered once and held onto for performance considerations.

    The model binder also solves this problem in a way that does not interfere with data annotation/validation attributes. They will work as you expect them in any other scenario.

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

Sidebar

Related Questions

i have an asp.net mvc page and i want to have a dropdown list
I have a data object that has many different List properties. I want to
I want to have a drop down box that has a list of different
I have two tables with list of urls fetched from different sources. I want
Hi i have a table where i list different values. Now i want to
We want to create a screen which should have different list views and the
I have the following problem. I have a list of different text lines that
I want to transform the dataset list, where the row is composed of different
Have/Want List Matching Algorithm I am implementing an item trading system on a high-traffic
I want to build a dynamic ListView (like a chat list with different layouts/bubbles).

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.