asp.net mvc - RxJS Observable.ajax post complex object to MVC -
i have problem post complex object rxjs observable ajax.
updatecashdesck():observable<somemodel>{ return observable.ajax({ body: {id:5,stocks:[{warehouseid:5,warehousename:"1235"}]}, url:this._apiserverurl, method:"post" }).map(r=>{ return new somemodel(r.response); }).catch((e,r)=>{ console.log(e); return observable.throw(e); }); }
the problem that. when ajax send request set content-type as:content-type:application/x-www-form-urlencoded; charset=utf-8 , request data post as:
id:5 stocks:[object object]
so mvc controller not see stocks (stocks: count=0).
how can change content-type in observable.ajax application/json?
if @ implementation, you'll see serializebody
method supports application/json
.
however, application/x-www-form-urlencoded
the default, if content-type
not specified.
so need specify application/json
explicitly:
observable.ajax({ body: { id: 5, stocks: [{ warehouseid: 5, warehousename: "1235" }] }, headers: { "content-type": "application/json" }, url:this._apiserverurl, method:"post" })
Comments
Post a Comment