将参数从角度http.get传递到C#控制器

时间:2019-09-05 04:07:02

标签: c# angular http

我想将参数传递给get函数。

我正在编写一个Rent项目,用户必须从日期,到日期等方面选择汽车制造商,并且通过这些参数,我需要搜索数据库。 HPPT.GET方法返回错误

//My Class
export class SelectParams {
    Gear: number;
    MakeYear: number;
    Maker: number;
    Degem: number;
    StartDate: string;
    EndDate: string;
    FreeText: string;
}

//My Http.get
Sparams: SearchParams = new SearchParams();
 let httpParams = new HttpParams().set('Id',this.Sparams.toString());    
    let options = { params: httpParams }; 
this.h.get(this.CarUrl,options).subscribe(
      code => {
        this.CarDbData = code;
        this.CarVec = this.CarDbData as Car[];
        console.log("this is select component");
        console.log(this.CarVec);
      });

//This is my c#
public class SelectParams
    {
        public int Gear;
        public int MakeYear;
        public int Maker;
        public int Degem;
        public System.DateTime StartDate { get; set; }
        public System.DateTime EndDate { get; set; }
        public string FreeText;
    }
 public IEnumerable<Car> Get(SelectParams SParams)
        {
            Car CarV = new Car();
            return CarV.SelectByParams(SParams);
        }

我收到HTTP 400错误请求。 我在做什么错了?

谢谢

1 个答案:

答案 0 :(得分:0)

我已经做了一些解决方案来解决这个问题,但我真的不知道有什么帮助。 我在类中添加了[DataContract]和[DataMember]-在此阶段没有帮助。 我创建了一个新的控制器并尝试将其激活。现在我进入了控制器发布功能。返回了参数,但没有输入参数。 由于我到达服务器的方式并不重要,因此我更改为HTTP.PUT。 我仍然对此有疑问。我看到有关多个实例的错误消息,而IIS不知道要激活哪个实例,因此我删除了控制器随附的默认put函数,现在一切正常。我现在要做的就是增强数据库中的select语句。