I am currently looking at Angular for the first time and trying to post a simple string to an MVC controller. However, when I try to post the string using the Angular client, I get a bad request response.
Test Class:
public class Test
{
public string Email { get; set; }
}
Posting via Angular client:
this.client.post<boolean>(this.baseUrl + 'weatherforecast/Test', { Email: Email });
This results in a bad request response.
[HttpPost]
[Route("Test")]
public bool Test([FromBody] string Email)
{
if (Email == "TestInput")
{
return true;
}
return false;
}
However this works:
[HttpPost]
[Route("Test")]
public bool Test([FromBody] Test EmailObject)
{
if (EmailObject.Email == "TestInput")
{
return true;
}
return false;
}
If I try posting the JSON as simply "StringValue" instead of { Email: "StringValue" }, I get an Unsupported Media Type response.
I imagine there is a simple solution, but is there a way to allow a string to be posted to an MVC controller without requiring it to be passed in as a class?