如何将模型从视图传递到按钮上的不同控制器单击“Mvc3” [英] How Can I Pass A Model From A View To A Different Controller On A Button Click In Mvc3
本文介绍了如何将模型从视图传递到按钮上的不同控制器单击“Mvc3”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将模型从视图传递到MVC3中按钮上的不同控制器
例如:
i有2个模型,如银行和员工
按钮单击员工视图我想将员工模型传递给银行控制器
怎么可能?
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??
推荐答案
你可以通过多种方式做到这一点。
1种方式:
如果您的员工模型已经存储在数据库中,那么您可以将该模型的ID作为查询字符串传递之后在第二个控制器内检索该模型。
2路
您可以使用 TempDate 来存储您的模型,之后从第二个控制器中检索它。
我写了一篇关于此的文章。请查看更多信息。
如何正确使用Asp.Net MVC TempData
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
这篇关于如何将模型从视图传递到按钮上的不同控制器单击“Mvc3”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文