添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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)
        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.

Yes, I realized that much. So I just surround the "Request" line with try and add the controller to "Code generation ignore list" ?

Edit:
I just copied a few lines of Post method to ServerMethodController. Thanks for your reply.