在 asp.net mvc 2 .在创建视图中添加新的关系记录
这是我的数据库设计。
联系方式
联系方式
联系人姓名
电子邮件地址
邮箱ID
联系方式
电子邮件文本
在创建视图中,我有“联系人姓名”字段和一个“添加电子邮件地址”按钮。
当我单击“添加电子邮件地址”时,会弹出一个窗口,执行 ajax 请求以获取地址字段。 我的问题是我需要在创建地址之前创建联系人,因为我首先需要一个 ContactID。有人知道如何进行吗?
我使用 asp.net MVC 2 和 Entity Framework 4
Here is my database design.
Contact
ContactID
ContactName
EmailAddress
EmailID
ContactID
EmailText
In the create View, I have ContactName Field and a button Add Email Address.
When I Click on the Add Email Address, there is a popup who perform an ajax request to get the Address Fields.
My problem is that I need to create the Contact before creating address because I need a ContactID first. Anybody know how to proceed ?.
I use asp.net MVC 2 and Entity Framework 4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您添加电子邮件时,您是否将其提交到您的服务器?或者您只是将该数据传递回父窗口(联系人姓名所在的位置),并将其放在姓名下方,以便在提交之前可见?
另一种选择是不打开弹出窗口,只需执行一些 JS Magic 并在联系人姓名正下方显示一个电子邮件字段(或者仅在联系人姓名下有一个选项文本框。
所以您会看到:
他们单击 +,然后显示:
提交后,您将获得您的联系人姓名和相应的电子邮件列表,然后创建您的电子邮件=。
When you add your email, are you submiting that to your server? Or are you just passing that data back to the parent window (where contact Name is), and putting it under the name so it's visible before submission?
Another option would be rather than open a popup window, just do some JS Magic and show an email field right below the contact name (or just have an option textbox under Contact Name.
So you'd see:
They click + and it goes:
On submission you'd have your contact Name and a nice list of emails to go with it. Create your contact and then create your emails. =
我的代码做了一些更复杂的事情,但非常相似。我所做的是在对话框关闭时创建并写入带有空白 ContactID 的电子邮件条目。然后,当我提交联系表单时,我会看到一个包含电子邮件 ID 的字段。在“联系人保存”操作中,我检查电子邮件记录,如果 contactID 字段为空,则插入 ContactID 并保存电子邮件记录。我使用相同的部分视图来创建和编辑,因此如果是编辑现有电子邮件,或向现有联系人添加新电子邮件,则 ContactID 字段已填充。
在这个简单的情况下,当用户关闭对话框以将信息保存到父表单上的隐藏字段时可能更有意义(如果您不希望它们显示,如果您确实希望它们显示,那么 Ryan 的建议是最好的)并且然后在联系人提交中创建并保存这两条记录。
如果这是“创建”,那么我真的不明白为什么你需要 AJAX 请求来获取值......
My code does something a bit more complicated, but very similar. What I do is create and write the email entry with a blank ContactID when the dialog is closed. Then when I submit my Contact form, I have a field with the EmailID. In my Contact Save action, I check the Email record and if the contactID field is empty, I insert the ContactID and save the Email record. I use the same partial view for Creating and Editing, so if it's Editing an existing email, or adding a new email to an existing contact, the ContactID field is already filled.
In this simple case, it may make more sense when the users closes the dialog to save the info to hidden fields on your parent form (if you don't want them displayed, if you do want them displayed then Ryan's suggestion is best) and then create and save both records on the Contact submit.
If this is a "Create" then I don't really understand why you need an AJAX request to get values...