Ajax parameters to the entity class corresponding fields

Source: Internet
Author: User

Before looking at the company's code, from the page Ajax parameters to the interface class, the interface class is received with an entity. I always thought C # would automatically recognize and assign values to fields of the same name.

I have discussed it with my friends and debated it. Friends think C # does not have this feature, and there is no such advanced matching mechanism. I think C # automatically assigns the same name because I use the direct value in the project and I haven't done any splicing or conversion. Friends disagree, so we think the code is seen.

Open VS, we start debugging, write an Ajax Js,url to write the path of the interface class, the parameter is a JSON, and then the interface class to receive JSON. When I write to the interface class, I want to receive the data from Ajax, and suddenly I'm blindfolded. How does a class receive data from a page, using XMLHttpRequest? Webhttprequest? The thing that has been taken for granted before has collapsed, obviously I did not use the time before the code to receive data, it should be directly assigned to AH? Why do I have to receive it when I write it myself?

So I went through the open source code and found that the key code was compiled, it doesn't matter, we can also decompile.

Finding the code of the call, I suddenly realized. The original project has already encapsulated the received data code, there is a dedicated to receive the AJAX data and convert it into an entity class. I have a little bit of admiration for the company's developers, encapsulation of the class to receive data, so that the interface class does not need as long as the processing logic, and do not care how to receive data, how to receive data, it is really greatly convenient for developers.

Then we begin to analyze, first of all, the parameters of Ajax to the JSON format to a special processing of data encapsulation, can be a. cs file, can also be a generic handler. It is convenient and simple to receive the JSON data from Ajax and then convert it to entity data internally.

Ajax parameters to the entity class corresponding fields

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.