错误内容:

Message=未找到与请求 URI“http://localhost:42914/api/Products/Login”匹配的 HTTP 资源。

MessageDetail=在控制器“Products”上找不到与该请求匹配的操作。

原因:

Post类型只能传递一个参数,且只能从Body中获取(加[FromBody]前缀)。

解决方案:

多个参数传递时需要放到实体类中,利用实体类获取传递过来的参数。

例:分页查询产品信息

实体类:

 public class ProductsPage
    {
        public int PageIndex { get; set; }

        public int PageSize { get; set; }

        public string strWhere { get; set; }

        public int TotalCount { get; set; }
        public List<ProductStore.Models.Product> ProductList { get; set; }
    }

接口方法:

public ProductsPage PostAllProductsByPage([FromBody]ProductsPage model)
        {
            model.ProductList = new List<Product>();
            model.ProductList = repository.GetAllByPage(model.strWhere, model.PageIndex, model.PageSize).ToList();
            model.TotalCount = repository.GetTotalCount(model.strWhere);
            model.PageIndex = model.PageIndex;
            model.PageSize = model.PageSize;
            return model;
        }

 

相关文章:

  • 2022-12-23
  • 2021-06-19
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-29
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-22
相关资源
相似解决方案