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!