Initially, I wrote it in a somewhat general manner. If you require more information, please let me know!
This is how my C# class appears 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; }));
}
Upon observing my network traffic, something altered the model:
ID => id
UnitID => unitId
// ...plus Lists...
Consequently, I updated my (frontend, typescript) model accordingly:
export class Recipe {
id: string;
unitId: string;
title: string;
}
Now that I have reached a stable state, I aim to send the data back to the server.
Next issue:
[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 it is missing UnitID
- yes, because it's written as unitId
The system expects a capital letter(UnitID
), but I am sending unitId
, so UnitID
ends up being null
(at least, that's my explanation)?
What should I do?