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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:13:10+00:00 2026-06-07T14:13:10+00:00

Hi all I have a base class called Vehicle and I have all the

  • 0

Hi all I have a base class called Vehicle and I have all the properties common to all vehicles in there and I have multiple derived classes called Car, Jeep which derive from Vehicle and add more properties

Ex:

    public class Vehicle
{
    public int Color { get; set; }
    public double Cost { get; set; }
}


public class Car : Vehicle
{
    public SelectListItem Option { get; set; }
}

I have a Page class in which I have a list of vehicles like this

public class Page
{
    public List<Vehicle> vehicles { get; set; }
}

My view is strongly types to the Page class so in my view I am looping over all the vehicles to display on page like this, This code is inside @using(Html.BeginForm()) so we post back user selections

    for(int i=0;i<Model.Vehicles.Count;i++)
{
    <div id="Question">
        @{
            @Html.EditorFor(m => m.Vehicle[i], VehicleConstants.GetTemplateName(Model.Questions[i]));
         }
    <br />
    </div>
 }

I am using one Editor template for each type of vehicle so the function call VehicleConstants.GetTemplateName just returns the name of the template to use based on the type of vehicle

This template simply writes the properties on the car class or Jeep class (Derived class + Base class)

The problem I am having is when the form is posted back I can only access the properties of Base class Vehicle in my controller I cannot get the value for properties of sub class car or Jeep.

        [HttpPost]
    public string ReadPost(Page page)
    {
    }

What is the best way to get these values autobinded when the form is posted back?

Is creating Custom Binder Class my only option? Is so can someone provide me some sample code as to how to do this? Any help much appreciated.

  • 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-06-07T14:13:12+00:00Added an answer on June 7, 2026 at 2:13 pm

    You will have to use a custom model binder for this. The default model binder doesn’t know which concrete type to instantiate. You may include a hidden field inside each row indicating the concrete type that your custom model binder would create. I have shown this in action here. By the way notice that by using the standard templates naming convention you could get rid of the for loop that you are using as well as the VehicleConstants.GetTemplateName method.

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

Sidebar

Related Questions

I have an abstract base class called Curve . There are three classes that
I have a base class and a dozen derived classes. All but one derived
I have an abstract base class that enforces certain operations on all derived classes.
I have an Object base class, and I have several derived classes called Item,
I have a base class called Geometry from which there exists a subclass Sphere
I have a base class called SCO that a number of classes inherit from.
I have a base-class called Element. Some other classes (like Label and Image) both
If I have a polymorphic base class called Base as well as classes Derived1
I have a base class A and classes B and C are derived from
I have a base class called BaseEvent and several descendants classes: public class BaseEvent

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.