11
angeben Ich könnte "TypeNameHandling = TypeNameHandling.Auto" in früheren Version von MVC verwenden. In MVC6, ich habe folgende KlasseWie polymorphe Typ in ASP.NET mvc 6
public class BaseClass {
public string Id {get;set;}
}
public class Foo : BaseClass {
public string Name {get;set;}
public string Address {get;set;}
}
public class Bar : BaseClass {
public string Account {get;set;}
public string Password {get;set;}
}
In meinem WebAPI wird JSON Ergebnis führen, das folgende
[
{Id: "1", Name: "peter", Address: "address1"},
{Id: "2", Account: "mary", Password: "1234"}
]
Aber ich möchte folgendes Ergebnis:
[
{$type: "Foo", Id: "1", Name: "peter", Address: "address1"},
{$type: "Bar", Id: "2", Account: "mary", Password: "1234"}
]
Sieht so aus, als ob es momentan einen Fehler gibt. Gespeichert hier: https://github.com/aspnet/Mvc/issues/3782 –
kannst du bitte deinen api-Code posten –