Angular frontend, then C# Backend with Syntax errors: HTTP Controller receiving a JSON object in the body

121 Views Asked by At

Trying to get a basic model of my functions working.

Frontend (Angular): the body data will be JSON of this class:

class BackendParams {
  listValues: any;

  constructor( netList: any ) {
    this.listValues = netList;
  }
}

Then a function creates the class object:

const params = new BackendParams(list);

then calls a (still in the front-end) Angular function to send it to the backend:

  onClickTest(params: any) {
    const A = 1;
    const B = 2;
    const NameString = 'test';
    const formData = new FormData();
    formData.append('NetworkList', JSON.stringify(params));
    let url = `${this.url}/CalibrationModel/1/2/SampleTest/TestModel`;

    this.http.post(url, formData).subscribe(  
          (data) => { 
            console.log(data);
          });
  }

BACKEND:

class BackendParams
{
    List<Constituent> listNetworkConstituents;

}

The following is image of the source code so you can see the syntax red underlines Note 2 syntax errors

I don't think the two are related (or are they?) but referencing the body parameters is of course essential.

And, of course, let me know anything else you see that might be a problem.

Thanks for your help. I learn a lot from you guys. Yogi

1

There are 1 best solutions below

2
On BEST ANSWER

If your method were marked as async then returning a bool would work. So public async Task<bool>..., but that isn't the case. However, as @JohnD91 said, if you're not using await in your method, it doesn't need to be async and it also doesn't need to return a Task.

The other problem is that parmsJSON is misspelled, because it's defined in the method signature as paramsJSON. You're missing the other a.