First I write it a little bit general, if you need more informations, tell me!
My C#-Class looks like this, when sent/received on the frontend:
public class Recipe : ICRUD
{
public Guid ID { get; set; }
public Guid UnitID { get; set; }
public string Title { get; set; }
// ... plus Lists ...
}
[Backend => Frontend]
Backend
[HttpGet("Recipe/[action]")]
public async Task<JsonResult> GetRecipes(ServerRequest filter)
Frontend
getRecipes(filter: ServerRequest) {
return this._http.get(this.myAppUrl + 'Recipe/GetRecipes' + '?' + this.toQueryString(filter))
.pipe(map((res: Recipe[]) => { return res; }));
}
I was looking at my network traffic and(something)changed the model:
ID => id
UnitID => unitId
// ... plus Lists ...
So I changed my (frontend, typescript) model as well:
export class Recipe {
id: string;
unitId: string;
title: string;
}
Now finally I got a stable state, and I want to sent the data back to the server.
Next problem:
[Frontend => Backend]
Frontend
createRecipe(recipe: Recipe) {
return this._http.post(this.myAppUrl + 'Recipe/CreateRecipe', recipe)
.pipe(map(res => { return res; }));
Backend
[HttpPost("Recipe/[action]")]
public async Task<HttpResponseMessage> CreateRecipe([FromBody]Recipe recipe)
Guess what ?
ModelState
is invalid, because he is missing UnitID
, yeah, because it's written like this unitId
He is expecting capital letter(...UnitID
..), but I am sending unitId
, then UnitID
is null
(at least this is my explaination) ?
What shall I do ?