The Web API returns JSON data, and the webapi returns json data.

Source: Internet
Author: User

The Web API returns JSON data, and the webapi returns json data.

For new Web API users, do not ignore ApiController.

In web APIs, if the return value of a method is an object, JSON data is automatically returned, for example:

The returned value is as follows:

{& Quot; Content & quot;: true, & quot; StatusCode & quot;: 200, & quot; RequestMessage & quot;: & quot; sample string 2 & quot "}

This is the defined Response class.

Public class Response <T> // where T: class {public T Content {get; set;} public HttpStatusCode StatusCode {get; set;} public string RequestMessage {get; set ;}}

 

There is another problem with the web API. It may be that I am too comfortable. If the newly created controller is not carefully viewed, the MVC4 or MVC5 controller will be selected by default, this will cause HelpPage to fail to display interfaces on the API page. Just modify the Controller to inherit the ApiController.

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.