相关疑难解决方法(0)

将整数数组传递给ASP.NET Web API?

我有一个ASP.NET Web API(版本4)REST服务,我需要传递一个整数数组.

这是我的行动方法:

public IEnumerable<Category> GetCategories(int[] categoryIds){
// code to retrieve categories from database
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的URL:

/Categories?categoryids=1,2,3,4
Run Code Online (Sandbox Code Playgroud)

c# arrays rest asp.net-web-api

397
推荐指数
12
解决办法
25万
查看次数

asp.net核心自定义模型绑定器只适用于一个属性

我的asp.net核心控制器有一个简单的模型:

[HttpPost]
public async Task<DefaultResponse> AddCourse([FromBody]CourseDto dto)
{
     var response = await _courseService.AddCourse(dto);
     return response;
}
Run Code Online (Sandbox Code Playgroud)

我的模型是:

 public class CourseDto
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Genre { get; set; }
    public string Duration { get; set; }
    public string Level { get; set; }
    public string AgeRange { get; set; }
    public string Notes { get; set; }
    public bool Active { get; set; }
    public string OrganisationCode …
Run Code Online (Sandbox Code Playgroud)

model-binding custom-model-binder asp.net-core-mvc asp.net-core

7
推荐指数
2
解决办法
2566
查看次数