Tuesday, June 11, 2013
How to Pass Multiple Parameters to Controller in MVC
There are several ways that we can implement this. I came across this because I had to pass 5 parameters to controller in my scenario. I got the solution using Ajax call inside the Jquery function. The Jquery function is as below.
Here I got all the values from UI controls using Jquery selectors and insert all of them in to javascripts array like this
the left side fields are same as the action parameters. Inside the ajax call the parameter values which are ready to be passed should convert into Json format. To convert into real object types, you should use the contentType: 'application/json; charset=utf-8', iside the ajax call.
Finally I created the controller action method and it worked fine in the development environment.
By using this method you can pass number of parameters to the controller action from the view. If you have any suggestions please leave a comment. Thank you.
Labels:
Action,
Ajax,
contentType,
Controller,
Javascripts,
JQuery,
Json,
MVC,
Parameters,
View
Subscribe to:
Post Comments (Atom)
Very useful contents. Thanks for sharing the knowledge :)
ReplyDeletepatta
ReplyDelete