简体   繁体   English

未找到与Angular 2中的请求URI匹配的HTTP资源

[英]No HTTP resource was found that matches the request URI in Angular 2

I am trying to post data to a web api with this structure: Ledger Header and a list of ledger details . 我正在尝试将数据发布到具有以下结构的Web api: Ledger Headerlist of ledger details This is my class in the web api for the two: 这是我在Web API中的两个课程:

public class PropertyLedgerDetail
{
    [Key]
    public int LedgerDetailID { get; set; }
    public int LedgerID { get; set; }
    public int? TransactionID { get; set; }
    public int? TransactionTypeID { get; set; }
    public double? Amount { get; set; }
    public double? PaymentAmount { get; set; }
    public int Month { get; set; }
    public int Year { get; set; }
    [StringLength(1000)]
    public string Remarks { get; set; }
    public bool Voided { get; set; }
    public DateTime? PostingDateTime { get; set; }
}

public class PropertyLeger
{
    [Key]
    public int LedgerID { get; set; }
    public int CollectingAgentID { get; set; }
    public int UnitID { get; set; }
    public int PaymentTypeID { get; set; }
    [StringLength(15)]
    public string ORNumber { get; set; }
    public int? VoidedLedgerID { get; set; }
    public bool? Voided { get; set; }
    [StringLength(100)]
    public string Remarks { get; set; }
    public DateTime? TransactionDateTime { get; set; }
    public DateTime? PostingDateTime { get; set; }
}

and this is to combine the two classes so I can receive it from my frontend: 这是结合这两个类,以便我可以从前端接收它:

public class AddLedger
{
    public PropertyLeger PropertyLedger { get; set; }
    public List<PropertyLedgerDetail> PropertyLedgerDetails { get; set; }
}

In my Angular front end, this is how I set up the properties to send: 在我的Angular前端中,这就是我设置要发送的属性的方式:

Get values from 2 forms 从2种形式获取价值

add() {
const PropertyLedgerModel: any = {
    CollectingAgentID: this.CollectingAgentID.value,
    UnitID: this.unitId,
    PaymentTypeID: this.PaymentTypeID.value,
    ORNumber: this.ORNumber.value,
    VoidedLedgerID: this.VoidedLedgerID.value,
    Voided: this.Voided.value,
    Remarks: this.Remarks0.value
}
const PropertyLedgerDetailsModel: any[] = this.dataSource;
const model: any = {
    PropertyLedger: PropertyLedgerModel,
    PropertyLedgerDetails: PropertyLedgerDetailsModel
}

this.pps.addLedger(model)
    .subscribe((data: any) => {
    debugger;
    if (data.StatusCode === 200) {
        this.ts.success(data.ReasonPhrase);
    } else {
        this.ts.error(data.ReasonPhrase);
    }
    },
err => {
    this.ts.error('An error has occured in saving payment(s): ' +err);
})
}

To actually send this to the web api 实际将此发送到Web API

addLedger(model: any) {
    debugger;
    const ep = this.rootUrl + '/api/newpropertyledger';
    const PropertyLedgerModel: any = model.PropertyLedger;
    const PropertyLedgerDetailsModel: any [] = model.PropertyLedgerDetails;
    const Model: any = {
        PropertyLedger: PropertyLedgerModel,
        PropertyLedgerDetails: PropertyLedgerDetailsModel
    };
    return this.http.post(ep, Model);
}

I created a debug point on the part that will receive the data: 我在将接收数据的部分上创建了一个调试点: 在此处输入图片说明

but the data from the front end doesn't reach the web api. 但是前端的数据无法到达网络API。 I just get this error: 我刚得到这个错误:

Message:"No HTTP resource was found that matches the request URI 'http://localhost:15232/api/newpropertyledger'."
MessageDetail:"No type was found that matches the controller named 'newpropertyledger'."

Please show me how to do it right. 请告诉我正确的做法。 Thank you so much. 非常感谢。

Assuming your api routing is correct ie any of the api methods are getting hit, this should help.. 假设您的api路由正确,即任何api方法都受到攻击,这应该会有所帮助。

addLedger(model: any) {
    debugger;
    const ep = this.rootUrl + '/api/newpropertyledger';
    const PropertyLedgerModel: any = model.PropertyLedger;
    const PropertyLedgerDetailsModel: any [] = model.PropertyLedgerDetails;
    const Model: any = {
        PropertyLedger: PropertyLedgerModel,
        PropertyLedgerDetails: PropertyLedgerDetailsModel
    };
    return this.http.post(ep, JSON.stringify(ledger));
}

public HttpResponseMessage NewPropertyLedger(string data)
{
             AddLedger ledger = JsonConvert.DeserializeObject<AddLedger>(data);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有找到与请求URI匹配的HTTP资源 - Web API + Angular - No HTTP resource was found that matches the request URI - Web API + Angular 找不到与请求URI&#39;MyUrl&#39;匹配的HTTP资源 - No HTTP resource was found that matches the request URI 'MyUrl' 获取没有与请求URI匹配的HTTP资源 - Getting No HTTP resource was found that matches the request URI 找不到与请求URI匹配的HTTP资源 - No HTTP resource was found that matches the request URI 找不到与webapi中的请求URI匹配的HTTP资源 - No HTTP resource was found that matches the request URI in webapi 未找到与请求URI匹配的HTTP资源,未找到与控制器匹配的类型 - No HTTP resource was found that matches the request URI, No type was found that matches the controller 路由错误:找不到与请求URI匹配的HTTP资源 - Routing error: No HTTP resource was found that matches the request URI 自定义“找不到与请求uri匹配的http资源”消息 - Customizing “No http resource was found that matches the request uri” message 未找到与请求 URI 匹配的 HTTP 资源,我需要解决方案 - No HTTP resource was found that matches the request URI, I need solutions 我收到错误“没有找到与请求 URI 匹配的 HTTP 资源” - I am getting error “No HTTP resource was found that matches the request URI”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM