title: Parent parameter used as Child Class in ASP.NET Core
body: <p>I have an HttpPost method where I'd like to be able to pass a Parent Class as parameter.
  From that parent class, I have 4 derived classes.
  The goal is to use only one HttpPost method to add any of these derived classes to the DB. Is this something possible ?</p>
  <p>I tried passing the Parent Class as parameter but then I'm losing all the attributes specific to the derived class.</p>
  <pre class="lang-cs prettyprint-override"><code>[HttpPost]
  public async Task&lt;ActionResult&gt; AddCustomField(CustomField customField)
  {
      // customField could be NumberCustomField, DropdownCustomField, StringCustomField, ...
  
      // This allows me to get a NumberCustomField but I lose all the attributes specific to the derived class
      NumberCustomField numberCustomField = JsonConvert.DeserializeObject&lt;NumberCustomField&gt;(JsonConvert.SerializeObject(customField));
  
      // This triggers an exception
      NumberCustomField numberCustomField = (NumberCustomField) customField;
  
      // I'd like to add any of the derived class to the DB, inheritance is set in the context (with a discriminator)
      _context.CustomFields.Add(numberCustomField); 
  
      return Ok();
  }
  </code></pre>
  <p>Here's my client side code :</p>
  <pre class="lang-js prettyprint-override"><code>// Form data structure sent to the back-end
  const initialCustomField = {
      label: '',
      type: null, // 'number', 'text', 'list' =&gt; used as discriminator
      category: 'tree',
      isGlobal: true,
      min: '0', // Specific to NumberCustomField
      max: '',
      step: '1',
      maxLength: '256', // Specific to StringCustomField
      isMultiple: false, // Specific to DropdownCustomField
      isNumeric: false,
      dropdownCustomFieldValues: [{ label: '', value: '' }]
  };
  
  // Axios request
  static addCustomField(customField) {
      return Axios.post(BACKEND_ENDPOINT + 'customFields/', customField, {
          headers: { 'Authorization': `Bearer ${new Cookies().get('token')}` }
      }).then(response =&gt; {
          return response.data;
      }, () =&gt; {
          return;
      });
  }
  </code></pre>
  <p>Should I use 4 different HttpPost methods or is it achievable ?</p>
  <p>Thanks a lot for your help !</p>