Send an object of derived class from Angular to a function that takes base class in C#

Discussão em 'Angular' iniciado por more21, Setembro 29, 2024.

  1. more21

    more21 Guest

    I have in C# a class App_Mail that inherits from the class App_action then I have a function that recieves an object of type App_Action I want to send from angular an object of type App_Mail to the function in C#

    When I send the Object - the function recognizes it as App_Action and ommits the extra attributes that are part of app_mail class.

    This is my code:

    C#:

    public class APP_Action
    {
    public string ActionID { get; set; }
    public string? Name { get; set; }
    }

    public class APP_Mail:APP_Action
    {
    public string? FromDisplayName { get; set; }
    public string? MailSubject { get; set; }
    public string? MailBody { get; set; }
    }

    public async Task<IActionResult> PostAsync([FromBody] APP_Action entity)
    {
    var a=entity.GetType();//returnes APP_Action
    }


    Now I am sending an object tof type APP_Mail, what can I do so that the C# recognizes that the object recieved is of the derived class?

    Continue reading...

Compartilhe esta Página