Parameters are not binding in post method to Model in .net core 3.1

Viewed 231

I am migrating from .net 4.8 to .net core 3.1 in previous framework this post call is working fine but here in .net core model is not binding.Although controller method is getting called but all the parametrs are null. Attaching logs also.

Could not find a value in the request with name '"parameters.configRowLimit"' for binding property '"Project.BusinessObjects.Areas.Reports.ViewParameters"."configRowLimit"' of type '"System.Int32"'

It is coming for every property. I dont get why it is looking into parameters.configRowLimit while from front end it is inside parameters.ViewParameters.configRowLimit

This is my front end parameters.

let ViewParameters = {};

    ViewParameters = {
      SqlQuery: SqlQuery,
      ViewObject: ViewObject,
      RowCount: totalCount,
      MaximumRowLimit: maximumRowLimit,
      AppInstanceID: $('#AppInstanceId').val(),
      FileName: metricName
    };

    let params = {};
    params = {
      ViewParameters: ViewParameters,
      Metrics: obj,
      fileTypes: value
    };
    

    let body = { parameters: params };
    let options = ({ headers: headers });
    return this.http.post(this._controllerMethod, body, options)`enter code here`

This is .net core controller method

  [FileDownload, DeleteFile]
    public ActionResult DownLoadQuery([FromBody] CurrentMetricDownload parameters)

Model CurrentMetricDownload

 public class CurrentMetricDownload
    {
        public FileTypes fileTypes { get; set; }
        public ExportFile File { get; set; }
        public TreeMetrics Metrics { get; set; }
        public ViewParameters Viewparameters { get; set; }
    }
1 Answers

if you give parameters to name of param in angular then in your model u need to have atrribute with this name too but your model name is parameters. So u need to assign params to body directly

let body = params;
let options = ({ headers: headers });
return this.http.post(this._controllerMethod, body, options)
Related