Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
How can i pass a Model from a View to a different controller on a button click in MVC3

For eg:

i have 2 Model like Bank and Employee
Button Click in Employee View i want to pass the Employee Model to the Bank Controller

How is it possible??
Posted

1 solution

You can do that in a number of ways.

1 Way:

If your Employee model already stored in a DB, then you can pass that model's id as query string and after that retrieve that model inside your 2nd controller.

2 Way

You can use TempDate to store your model and after that retrieve it from the 2nd controller.

I have written an Article about This.Please check that for more info.

How to use Asp.Net MVC TempData Properly
 
Share this answer
 
Comments
fiashieen 22-Jan-14 7:52am    
Much Thanks for the reply. Actually my requirement is, when i enter some details in Employee View and directed to Bank Controller to add some bank details and when i redirected back to the Employee View i have to persist the details i have entered earlier.Is that possible without the HTTPPost method??
Sampath Lokuge 22-Jan-14 7:58am    
If you don't like httpPost Then you have to use jQuery Ajax call. Is it OK for you ?
fiashieen 22-Jan-14 8:07am    
ok thank you.I will try both..:)
fiashieen 22-Jan-14 23:23pm    
Its working...!!!!Thanku soo much...:)
Sampath Lokuge 23-Jan-14 1:32am    
Glad to hear that it helped.Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900