The difference between [ASP] MVC and Web APIs

Source: Internet
Author: User

The action of the ASP. NET MVC and Web API is very different from getting the data that is passed in from the foreground

The foreground uses Ajax to initiate post requests to the background Content-type:application/json

Use the following JSON object

{    "user":    {        "Username": "XXX",        "Password": "xxxx"    }}
  {        "Username": "XXX",        "Password": "XXX"    }

Public         string Login (user user)        {            try            {                sign.login (user);            }             Catch (loginexception e)            {                return  e.message;            }             // Save Login Status            true );             return "Success";        }

In MVC, both formats can be used to obtain the user's Username,password,

In Webapi, using the first one to get to the user's Username,password is null, the second can get to the user's Username,password.

In MVC

        Public ActionResult Test (intint int c)        {            return  View ();        }

This Aciton can pass a JSON like this.

{  "a": 1,  "B": 2,  "C": 3}

Using this parameter in Webapi, you will be prompted not to find the configured action, perhaps Webapi can only define parameters of the reference type in addition to the ID defined in the route (using the URL parameter), and

  {        "Username": "XXX",        "Password": "XXX"    }

The JSON in this format is passed in to receive.

The difference between [ASP] MVC and Web APIs

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.