This is my first venture into the world of .Net Core Angular projects, so I apologize if my question appears to be too basic. Despite researching similar issues, I am still unable to resolve my problem, which leads me to believe that I must be making a mistake somewhere.
Here's the scenario: I've set up a .Net Core 3.0 Angular project in Visual Studio with a select menu that triggers a POST request upon selection. However, on the controller side, I always receive a NULL value from the POST request.
Below is a snippet of my HTML code:
<select class="form-control" (change)="languageChanged($event.target.value)">
<option *ngFor="let language of languages | keyvalue:returnZero" value="{{language.key}}">{{language.value}}</option>
</select>
When it comes to handling the POST request on the client side, here are the methods I have attempted:
this.http.post("Language", lang).subscribe(result => {
console.log(result);
}, error => console.error(error));
and
this.http.post<LanguageInterface>("Language", lan).subscribe(result => {
console.log(result);
}, error => console.error(error));
where
export interface LanguageInterface { language: string; }
As for the server-side implementation:
public class Language
{
public string language { get; set; }
}
In terms of the HTTP post action, I have experimented with two different approaches:
public IActionResult Post(Language lan)
{
// logic
return Ok();
}
and I also tried modifying the method signature to this:
public async Task<IActionResult> Post([FromForm]Language lan)
I would greatly appreciate any assistance you can provide! Thank you for taking the time to read through my query!