ASP. net mvc (0009): Obtain the request data of MVC.

Source: Internet
Author: User

 

Generally, the request data includes form data, query string parameter values, and cookies.

Like ASP. NET, you can still use the Request attribute to obtain the Request data.

The Controller has a Request attribute and a Request attribute in the view page, which can be used to obtain Request data.

 

You can use Request. Form to obtain the specified Form data, as shown in the following code:

 

String userName = this. Request. Form ["UserName"];

String password = this. Request. Form ["Password"];

You can use Request. QueryString to obtain the specified query string parameter value, as shown in the following code:

 

String Country = this. Request. QueryString ["Country"];

You can use Request. Cookies to obtain the specified Cookie value. The following code:

 

String UserName = this. Request. Cookies ["UserName"]. Value;

Except for the Request. Form data listed above,

Request. QueryString get the query parameter value,

In addition to the Cookie value obtained by Request. Cookies,

You can also use the fuzzy query Request to query the Request data.

For example, the following code:

 

String userName = this. Request ["UserName"];

String password = this. Request ["Password"];

This is the UserName and Password,

It may be form data, query parameter values, or Cookie values.

Although this method causes us to enter less code, it may cause some performance loss.

Therefore, if we know exactly which data in the form data, query parameter value, and Cookie is to be obtained,

Use the corresponding set attribute to obtain it!

 

To learn more, you can watch the Demo Video.

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.