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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:32:16+00:00 2026-06-12T22:32:16+00:00

I have a requirement for users to edit a list of quotes for a

  • 0

I have a requirement for users to edit a list of quotes for a lead, the quotes can be different types such as:

  • QuoteForProductTypeA
  • QuoteForProductTypeB

All quote types share a common base class, such as QuoteBase.

I have my quotes displaying fine on the front end, and appear to post back the correct data too.

However, on the server it doesn’t obviously doesn’t know which subclass to use, so just uses the base class.

I think i need some kind of custom model binder for WebApi to check for a hidden field such as ModelType which contains the type of the object in the collection, the model binder then creates a new object of this type and binds the properties from my posted values to this object.

However, i am stuck at this point with very little documentation / blogs on how to do this.

I have checked the source code for WebApi to see if i can extend a default model binder, but any defaults are sealed classes.

I can only implement IModelBinder by the looks of it, i can create the correct model type by looking for a value called ModelType, but then i’m not sure how to fill the rest of the values in my subclasses, if there was a default model binder i was inheriting from i would just call the base classes bind method.

  • 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-12T22:32:17+00:00Added an answer on June 12, 2026 at 10:32 pm

    If your post collection comes from request body, it won’t go through model binder. Web API will use formatter to deserialize the content.

    If you just want to support json, it’s quite easy. Just add following code to your web api config:

    config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto;
    

    The setting will let json.net to save type name in the payload if the runtime type is different with the declare type. When you post it back, json.net will deserialize the payload to the type you specified in the payload.

    A sample payload looks like:

    {"$type":"MvcApplication2.Models.Car, MvcApplication2","SeatCount":10,"WheelCount":4,"Model":0,"Brand":null}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a requirement to log IP address information of all users who use
I have a view to display a list of items. The user can edit,
I have a requirement to allow users to open word document from web page
I have a requirement to allow users to browse directories on our file server,
We have a business requirement that some users be automatically logged out of our
I have a requirement where I have to register users first via email. So,
I have a requirement for an explicit logout button for users in a ASP.NET
I have requirement where when a user enter new item in a list first
I have looked all of the place for this and I can't seem to
Hi guys I have 2 different List 1 that holds items that I see

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.