请问为什么我的web api应用不能访问单个查询,每次调用都是全部数据出来
模型定义 Brand.sc
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace TerminalApp.Models
{
public class Brand
{
public string machine_brand { get; set; }
}
}
控制器BrandsController.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TerminalApp.Models;
namespace TerminalApp.Controllers
{
public class BrandsController : ApiController
{
public IEnumerable<Brand> GetAllBrands()
{
string sql = "select machine_brand from terminal_models_brand order by machine_brand";
DataTable BrandTable = PublicFunction.GetVehicleData(sql);
//查询表达式的写法
var AllBrands = from dt1 in BrandTable.AsEnumerable() //查询
select new Brand { machine_brand = dt1["machine_brand"].ToString() };
return AllBrands;
}
public IHttpActionResult GetBrand(string abrand)
{
string queryString = "select machine_brand from terminal_models_brand where machine_brand='" + abrand + "' order by machine_brand";
DataTable BrandTable = PublicFunction.GetVehicleData(queryString);
if (BrandTable == null)
{
return NotFound();
}
var OneBrand = from dt1 in BrandTable.AsEnumerable() //查询
select new Brand { machine_brand = dt1["machine_brand"].ToString() };
return Ok(OneBrand);
}
}
}
测试时使用的路径是http://localhost:50710/api/brands/LG
与http://localhost:50710/api/brands
返回的结果是一样的,都是把所有记录调用出来了,而不是设想的,第一句应该只调用LG的一条记录

通过设置断点可以看出,访问地址http://localhost:50710/api/brands/LG
根本就没有访问public IHttpActionResult GetBrand(string abrand) 这个函数
请问这是什么原因?
谢谢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace TerminalApp.Models
{
public class Brand
{
public string machine_brand { get; set; }
}
}
控制器BrandsController.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TerminalApp.Models;
namespace TerminalApp.Controllers
{
public class BrandsController : ApiController
{
public IEnumerable<Brand> GetAllBrands()
{
string sql = "select machine_brand from terminal_models_brand order by machine_brand";
DataTable BrandTable = PublicFunction.GetVehicleData(sql);
//查询表达式的写法
var AllBrands = from dt1 in BrandTable.AsEnumerable() //查询
select new Brand { machine_brand = dt1["machine_brand"].ToString() };
return AllBrands;
}
public IHttpActionResult GetBrand(string abrand)
{
string queryString = "select machine_brand from terminal_models_brand where machine_brand='" + abrand + "' order by machine_brand";
DataTable BrandTable = PublicFunction.GetVehicleData(queryString);
if (BrandTable == null)
{
return NotFound();
}
var OneBrand = from dt1 in BrandTable.AsEnumerable() //查询
select new Brand { machine_brand = dt1["machine_brand"].ToString() };
return Ok(OneBrand);
}
}
}
测试时使用的路径是http://localhost:50710/api/brands/LG
与http://localhost:50710/api/brands
返回的结果是一样的,都是把所有记录调用出来了,而不是设想的,第一句应该只调用LG的一条记录

通过设置断点可以看出,访问地址http://localhost:50710/api/brands/LG
根本就没有访问public IHttpActionResult GetBrand(string abrand) 这个函数
请问这是什么原因?
谢谢
...全文
相关推荐
如何在WPF应用程序中通过HttpClient调用Web API
本教程是继使用HttpClient调用Web API只有的补充教程,主要讲解了如何在WPF中异步调用Web API且不阻塞主线程。
高德API在web端的调用(定位方面)
高德API的调用,实现了模糊查询,地址精确定位,经纬度定位
API是什么,怎么调用API,API调用详解
API是什么,怎么调用API,API调用详解。本文档详细解释了API是什么,以及如何调用API。讲解API的数据格式以及各个返回码的含义。
Xamarin android调用web api入门示例
Xamarin android调用web api入门示例,使用ListView调用webapi,使用动态数据做增删改查
通过HttpClient 调用ASP.NET Web API示例
本篇文章主要介绍了通过HttpClient 调用ASP.NET Web API示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧


Web Services
