0

I have been trying to expand on my Account Controller for my web api however I cannot seem to get new actions to work. I just want an action that intakes a string. So I wrote my action like this:

Update: This action works if I remove the parameter (String val) now = ()

[AllowAnonymous]
    [Route("Stuff")]
    public IHttpActionResult Stuff(String val)
    {


        return Ok();
    }

Then in my AngularJS I wrote a function to call into my action

function storeConnID (event, data){
        return $http({
            url: State.Endpoint + "/api/account/stuff",
            method: "POST",
            headers: {
                'Authorization' : 'Bearer '+ State.User.Access_Token
            },
            data: {
                val: data
            }
        }).then(function (res) { }, function (err) {
            console.log(err);
        });
    };

The url after it is all formatted is as such:

https://localhost:44375/api/account/stuff

Every other action in my controller works however I cannot create new ones?

Bailey Miller
  • 1,376
  • 2
  • 20
  • 36

1 Answers1

0

Continued research:

Javascript isn't simply sending in a string, it is sending a json object with a key/value pair. The web api action doesn't understand this object when I am looking for a string.

My proposed solution:

[AllowAnonymous]
    [Route("Stuff")]
    public IHttpActionResult Stuff(Dynamic Data)
    {


        return Ok();
    }

By changing the input to a dynamic type the data can come as any form of object.

Bailey Miller
  • 1,376
  • 2
  • 20
  • 36