ljj82livecn
FIFA_Online
采纳率66.7%
2018-07-20 03:27 阅读 744

asp.net core angular 如何往服务端传集合数据

5

请问一下angular HttpClient post往服务器端传数据时如何传集合,不用序列成字符串,然后再反序列的方式
服务端:

    [HttpPost("create")]
    public async Task<long> InsterSysOrgTypeAndFunction(List<SysOrgTypeAndFunction> sysOrgTypeAndFunctions)
    {
        return 0;
        //return await Task.Run(() => new DSysOrgTypeAndFunction(Configuration.GetConnectionString("DefaultConnection")).Insert(sysOrgTypeAndFunction));
    }

客户端:
import { Injectable } from "@angular/core";
import { HttpClient, HttpParams } from "@angular/common/http";
import { Observable } from "rxjs/Observable";

@Injectable()
export class SysOrgTypeAndFunctionService {
constructor(private http: HttpClient) { }

// 查询信息
getSysOrgTypeAndFunctions() {
    return this.http.get<any>('api/SysOrgTypeAndFunction/get-users');
}

//
// 保存信息
//
SaveSysOrgTypeAndFunction(formData: FormData, operation: Operation) {

    switch (operation) {
        case Operation.Create:
            return this.http.post<boolean>('api/SysOrgTypeAndFunction/create', formData)
                .catch(this.errorHandler);
        case Operation.Modify:
            return this.http.post<boolean>('api/SysOrgTypeAndFunction/modify', formData)
                .catch(this.errorHandler);
        case Operation.Delete:
            return this.http.post<boolean>('api/SysOrgTypeAndFunction/delete', formData)
                .catch(this.errorHandler);
    }
}

errorHandler(error: Response) {
    console.log(error);
    return Observable.throw(error);
}

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐