【发布时间】:2021-10-21 21:52:16
【问题描述】:
我想根据查询参数值接受与正文不同的模型类型。
例子:
[HttpGet]
[Route("GetSystemdetails")]
public string Getdeatils([FromBody] SystemDetail sysdetails, string type)
{
//some code here
string details = getdetails(sysdetails);
}
// abc model
public class abc
{
public int UserID { get; set; }
public string Email { get; set; }
}
//xyz model
public class xyz
{
public int xyzid { get; set; }
public string systemval { get; set; }
public string snum { get; set; }
}
键入abc 和xyz 将拥有自己的模型。因此,基于type,我在查询参数中收到我想选择模型并继续。
示例网址:
localhost/GetSystemdetails/type=abc
localhost/GetSystemdetails/type=xyz
我想创建一个 new model SystemDetail 来保存这两个模型(xyz 和 abc)并根据系统选择它们。
我想知道有哪些可能的方法来实现这种要求,而无需在控制器中创建多个方法(我不想更改 URL 的格式)。
【问题讨论】:
标签: c# .net asp.net-web-api microservices