我的webcore应用程序中有一个api控制器:
[Route("api/[controller]")]
public class DataController : Controller
{
protected ApplicationDbContext dbContext;
public DataController(ApplicationDbContext dc)
{
dbContext = dc;
}
[HttpGet("Categories")]
public List<Category> GetCategories()
{
var l = dbContext.Categories.OrderBy(c => c.Name).ToList();
return l;
}
}
和班级
public class Category
{
public long Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
当我调用控制器操作以获取类别时,在响应中,属性名称全部变为大写。那是: id变成id 名字变成名字 描述变成描述。
**编辑: 我也尝试过:
[HttpGet("Test")]
public IActionResult Test()
{
var l = dbContext.Categories.OrderBy(c => c.Name).ToList();
return Json(l);
}
而且这些财产全部取消了资本金
答案 0 :(得分:0)
/// <summary>
/// Welcome Note Message
/// </summary>
/// <returns>In a Json Format</returns>
public JsonResult WelcomeNote()
{
Category cs = new Category();
cs.Id = 123456;
cs.Name = "ExampleName";
cs.Description = "Abcd";
return Json(cs, JsonRequestBehavior.AllowGet);
}