开发者

Passing Data Between Views and Controllers

开发者 https://www.devze.com 2022-12-19 18:01 出处:网络
I\'m working on an application that manages people and their spouses, if married.Essentially a person will be entered and then from that person I want to be able to add a spouse.My database schema is

I'm working on an application that manages people and their spouses, if married. Essentially a person will be entered and then from that person I want to be able to add a spouse. My database schema is like this. Persons (Person_ID, Name, BirthDate, etc...), Marriages(Marriage_ID, Husband_ID, Wife_ID, Date).

The process is Add a Person then, if married, add spouse. So I have a Person Controller with an ADD action (get and post). When Add Spouse is selected in the Details view t开发者_Python百科he AddSpouse Action is called which will create the new person (spouse) and then create the marriage. MY issue is that I need to pass the PersonID of the original person to the AddSpouse action in order to create a marriage. What is the best way to do that?


You can pass your personID in ViewData like this :

ViewData["PersonID"] = 1

and recover it in AddSpouse action

var id = ViewData["PersonID"]

0

精彩评论

暂无评论...
验证码 换一张
取 消