C # WEBAPI----H5_app Background production (2)--parameter transfer (for lazy WEBAPI parameter transfer not a supplement)

Source: Internet
Author: User

(2) Question two: the way to pass the parameters;

Http://www.cnblogs.com/landeanfen/p/5337072.html's supplement to this article

Test one as follows:

1) The backend code is as follows,

Note 1: There can be only one parameter in the method in the API, which cannot occur like this

public Object Post (logininfo user,string name)
  Public classLogincontroller:apicontroller {[HttpPost] Public Objectpost (logininfo user) {return user.strpwd;        }        Public classLogininfo { Public stringstruser {Get;Set; }  Public stringstrpwd {Get;Set; } }}

Send the request as follows: Send data in JSON format, write your own request header, note Contexttype:application/json, and represent the data sent in JSON format.

Note 1: The default path is set to Routetemplate: "Api/{controller}/{id}",

To be set to Routetemplate: "Api/{controller}/{action}/{id}" to request a method

The returned data received is successful.

Use the jquery test to initiate a POST request: Send data directly in the format of the object, and jquery will automatically be sent according to the format sent to the appropriate format.

The code is as follows:

<script src="Jquery-2.2.0.min.js"></script> <script>varPostData = {struser:"13443", Strpwd:"Jim" }; function Login () {$.ajax ({type:"Post", URL:"Http://localhost:61083/api/Login/Login",               //contentType: "Application/json",Data:postdata, success:function (data, status) {}        }); }    </script>"Text-align:center;"> <div> user name: <input type="text"Id="Txt_username"Value="Admin"/></div> <div> Password: <input type="Password"Id="Txt_password"Value="123456"/></div> <div><input type="Button"Value="Login"Id="Btn_login" class="Btn-default"onclick="Javascript:login ()"/></div> </div></body>

C # WEBAPI----H5_app Background production (2)--parameter transfer (for lazy WEBAPI parameter transfer not a supplement)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.