【发布时间】:2018-11-13 12:26:12
【问题描述】:
我想模仿现有网络服务的行为。这是一个非常简化的示例,显示了我想要实现的目标。
我使用 ASP.Net Web API 路由:用它配置路由非常简单。
要求,第 1 部分:查询:
GET whatever.../Person/1
应返回 JSON:
Content-Type: application/json; charset=utf-8
{"id":1,"name":"Mike"}
这是小菜一碟:
public class Person
{
public int ID { get; set; }
public string Name { get; set; }
}
// In ApiController
[HttpGet]
[Route("Person/{id}")]
public Person GetPerson(int id)
{
return new Person
{
ID = id,
Name = "Mike"
};
}
要求,第 2 部分:查询:
GET whatever.../Person/1?callback=functionName
应返回 javascript:
Content-Type: text/plain; charset=utf-8
functionName({"id":1,"name":"Mike"});
任何想法如何实现这一点(第 2 部分)?
【问题讨论】:
标签: c# asp.net-mvc asp.net-web-api asp.net-mvc-routing