locked
How can POST multi parameters? RRS feed

  • Question

  • User-1466065877 posted

    Hi, I would like to post multi parameters to the method but I fails.

     

        public class login_in
        {
            public string user_code { get; set; }
            public string user_password { get; set; }
        }

            public login_return PostTest([FromBody]login_in tmp)
            {
                try
                {
                    return new login_return { user_code = tmp.user_code, user_name = "User 1" };
                }
                catch (Exception ex)
                {
                }
                return null;
            }
                RouteTable.Routes.MapHttpRoute(
    name: "Testing",
    routeTemplate: "Testing",
    defaults: new
    {
        controller = "Products",
        action = "PostTest"
    }
    );


    May I know is there anythings wrong on this coding?

    Thanks.

    Tuesday, September 1, 2015 12:30 AM

Answers

  • User-1466065877 posted

    Last'y, find out that the coding is correct. It fails to post value to api because the json string cannot be posted correctly.

    In Advanced Rest Client, we have to use "{}" to include the object because post data to api.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 2, 2015 2:12 AM

All replies