Answered by:
How can POST multi parameters?

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
-
User-138061656 posted
hi @PhC ,
did you try FormCollection? You can achive all form parameters with FormCollection.
usage like this :
public login_return PostTest(FormCollection collection) { try { return new login_return { user_code = collection["user_code"], user_name = "User 1" }; } catch (Exception ex) { } return null; }
Tuesday, September 1, 2015 2:13 AM -
User-1466065877 posted
No, it also does not work. It seems it cannot post the data to method correctly. The "collection" parameter is null.
Tuesday, September 1, 2015 2:56 AM -
User1724605321 posted
Hi phc ,
You could also refer to link below for Parameter Binding in ASP.NET Web API:
http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api .
Best Regards,
Nan Yu
Tuesday, September 1, 2015 3:12 AM -
User-1466065877 posted
Not sure the reason,
I try to post a value (using Advanced Rest Client) to default post method but fail.
public void Post([FromBody]string value) { }
RouteTable.Routes.MapHttpRoute( name: "Post", routeTemplate: "Post", defaults: new { controller = "General", action = "Post" } );
Is there any wrong when I post the value?
Tuesday, September 1, 2015 3:46 AM -
User1724605321 posted
Hi phc ,
I try to post a value (using Advanced Rest Client) to default post method but fail.What is the error message ? Please refer to link below for a detail steps about how to use Routes and Web API Controllers :
http://www.mikesdotnetting.com/article/261/integrating-web-api-with-asp-net-razor-web-pages .
You could also refer to links below details:
http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection .
http://www.codeproject.com/Articles/624180/Routing-Basics-in-ASP-NET-Web-API .
Best Regards,
Nan Yu
Tuesday, September 1, 2015 9:48 PM -
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