ASP. net mvc sends parameters to the server for details and examples, asp. netmvc

Source: Internet
Author: User

ASP. net mvc sends parameters to the server for details and examples, asp. netmvc

ASP. net mvc transmits parameters to the server

ASP. net mvc transmits parameters to the server. You can refer to and use methods that suit your needs for frontend and server writing. When you pass only one or two parameters, you may feel that there is nothing. If there are many parameters in a method, you can consider the model, and the front-end can consider the object. In this way, you can compare it with the attribute name of the model, good maintenance and fewer errors.

All the following demos are performed in the ASP. net mvc environment.

In the controller, create two actions. The second Action is a method with four parameters. In a normal development environment, you have to write several parameters if you have several parameters.

In the view, you need to pass the value entered or selected by the user to the Post1 () method of Action.

In the preceding code example, the highlighted part is transmitted using four parameters and json.

The result is returned after processing by the server:

If you have some knowledge about javascript objects, you can also write as follows:

After the modification, the execution results are the same. It only applies the javascript Object form. Now that it is in the ASP. net mvc environment, we should think of a Model. We can write the passed parameters as a Model.

This mainly solves the problem of the Controller's Action parameters. If there are many parameters, the more parameters the Action carries. In case of method overloading, You have to match multiple actions. If you use the Model, you do not need to care about the number of parameters. You only need to use the model as the parameter.

Create a model:

Then in the controller, you can write it:

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

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.