asp.net mvc transfer parameters to service study solutions and examples _ practical skills

Source: Internet
Author: User

asp.net mvc transfer parameters to the service side

asp.net mvc transfer parameters to the service side, the front-end and the service side of the writing, you can refer to and adopt suitable for your needs. When you pass only one or two parameters may feel that there is nothing, if a method with more parameters, you can consider model, the front-end can be considered objects, so with the model of the property name than right, good maintenance and fewer errors.

All of the following demos are performed in the ASP.net MVC environment.

In the controller, create two action, the second action is a method with four parameters, in the normal development environment, you have several parameters, you have to write a few parameters.

In the view, you need to pass the value that the user fills in or selects to the action Post1 () method.

In the code example above, the emphasis tag section is routed with JSON with four parameters.

Demo, the result is the result of a service-side process that returns:

If you know something about JavaScript objects, you can also write this:

After the modification, the results of the execution are the same. It's just a JavaScript object form applied. Now that it is in the asp.net MVC environment, we should think of a model. We can put the parameters of passing, write a model

This is mainly to solve the problem of the Controller's action parameters, if there are many parameters, the action with the number of parameters cited. If you encounter a method overload, you will have to match a lot of action. If you use model, you do not need to ignore the number of parameters, only the model as a parameter can be.

Create a good model:

Then in the controller, you can write:

Thank you for reading, I hope to 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.