I have a method in ServerMethodsController.cs that execute Post method of a controller.
CmdDetailsController cdc = new CmdDetailsController(this.MyData);
IActionResult cdc_ar = cdc.Post(cmd);
I always get BadRequestObjectResult ("Object reference not set to an instance of an object.") for the result but the data was recorded in database.
And when I trace it to CmdDetailsController's Post method
[HttpPost]
[EnableQuery(MaxExpansionDepth=10,MaxAnyAllExpressionDepth=10,MaxNodeCount=1000)]
public IActionResult Post([FromBody] Models.MyData.CmdDetail item)
{
try
{
...
Request.QueryString = Request.QueryString.Add("$expand", "Change");
return new ObjectResult(SingleResult.Create(itemToReturn))
{
StatusCode = 201
};
}
catch(Exception ex)
{
ModelState.AddModelError("", ex.Message);
return BadRequest(ModelState);
}
}
It's the Request.QueryString line that triggered the exception.
I know the Request object is null because I'm not calling the method via http.
How to directly execute a controllers Post method (or any method) without triggering the null exception in Radzen?
Thanks.