0

I would like to pass multiple values to the following web api using angularjs typescript.

// POST api/values
        public void Post([FromBody]string value1, [FromBody]string value2)
        {
        }

I would like to call the above method something like this

$http.post('api/values', ???)

As I need to do some validations on the page by passing multiple parameters to the database. I also tried with GET instead of post but didn't work for me.

Please share your thoughts.

Thank you. Hari C

2 Answers 2

1

You can't read multiple values "FromBody". Instead you should define "Request" class with all needed parameters:

    public class Request
    {
        public string Value1 { get; set; } 
        public string Value2 { get; set; } 
    }

    //POST api/values
    public void Post([FromBody]Request request)
    {
    }

And then like Aran said you can go this way

$http.post('api/values', {Value1:"foo", Value2:"bar"});
Sign up to request clarification or add additional context in comments.

Comments

0

Use the data property (the second argument of $http.post) to pass your parameters:

$http.post('api/values', {x:"foo", y:"bar"});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.