There are many questions about this already on this forum. I have read them but i couldn't solve my issue, so I'll try and ask again in here.
I'm building an Angular + ASP Core app. I have used FromBody succesfully on other requests already, but for some reason this particular one isn't working.
Here's my model class:
export interface CreateEventModel {
name: string;
description: string;
categoryId: number;
typeId: number;
price: number;
startDate: Date;
endDate: Date;
imageContent: Blob;
imageMimeType: string;
}
Here's how i'm sending to server:
plan() {
// ...
this.net.post('Event/Create', this.model).subscribe((res: Response | any) => {
if (res.status == 200 || res.isOk == true) {
this.toasterService.pop('success', 'Sucess', "IS NOT NULL!");
}
}, err => { // Show error });
}
Heres my '.net.post' Service in the Request, in case you're wondering:
post<T>(url: string, data: any): Observable<T> {
return this.basePut<T>(url, data);
}
// Does header, with JWT
private basePut<T>(url: string, data: any): Observable<T> {
let options = this.doHeaders();
return this.doSub(this.http.post(this.doUrl(url), data, options));
}
private doSub<T>(obs: Observable<Response>) {
var ob1: Observable<T> = obs.map(this.extractData)
.catch(this.handleError);
return ob1;
}
Heres my JSON output:
{
"imageContent": {},
"imageMimeType": "image/jpeg",
"name": "MyTitle",
"typeId": 3,
"categoryId": 3,
"description": "My Description",
"price": 0,
"startDate": "2018-08-10T15:55:00.000Z",
"endDate": "2018-09-26T15:55:00.000Z"
}
Here's my controller method:
[HttpPost, Authorize(Roles = "Admin,Planner")]
public IActionResult Create([FromBody]CreateEventModel model)
{
// Do stuff, but 'model' is always null
}
Lastly, my C# Model
public class CreateEventModel: ICreateEventModel
{
public string Name { get; set; }
public string Description { get; set; }
public int CategoryId { get; set; }
public int TypeId { get; set; }
public decimal? Price { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public byte[] ImageContent { get; set; }
public string ImageMimeType { get; set; }
}
I'm not sure what could be wrong. Any help would be greatly appreciated.