MVC3/EF4:编辑器 对于对象的字段,例如 Employee.Supervisor

发布于 2024-12-07 00:34:31 字数 614 浏览 4 评论 0原文

我的数据库有一个 Employee 表,其中有一列 SupervisorId,正如您所期望的那样,它是 Employee 表的外键。

目前,在我的 Create.cshtml 视图/表单中,对于主管字段,我有一个组合框,其中 Employee.Name 作为数据文本,Employee.EmployeeId 作为数据值。然后在控制器中我这样做:

     ViewBag.SupervisorId = new SelectList(db.Employees, "EmployeeId", "Name");

这实际上工作得相当顺利,但显然它根本无法很好地扩展。

我想要的只是在不可编辑的文本框中显示主管姓名,然后有一个打开 div 的浏览按钮(最坏的情况,我将使用弹出窗口),允许他们搜索员工并选择它们 ->将他们的名字放在文本框中。否,主管 ID 不可见。我有点不知道如何去做这件事。

对于搜索,我想当选择结果时,我会使用 JS 设置一个带有主管 id 的隐藏表单变量?或者如何存储主管值,以便在单击提交时在员工上正确设置它?

有人可以指出我正确的方向吗?我不需要编码的解决方案,而只是一个概述。如果有帮助的话,我正在使用免费的 Telerik 控件。

谢谢。

My database has an Employee table, which has a column SupervisorId, which as you would expect is a foreign key into the Employee table.

Currently, in my Create.cshtml view/form, for the supervisor field, I have a combo box with Employee.Name as the data text, and Employee.EmployeeId as their data value. Then in the controller I do this:

     ViewBag.SupervisorId = new SelectList(db.Employees, "EmployeeId", "Name");

This actually works pretty slick, but obviously it won't scale well at all.

What I want is to just display the supervisor name in a non-editable text box, and then have a browse button that opens a div (worst case scenario, I'll use a pop up), that allows them to search an employee and select them -> placing their name in the text box. No the ID of supervisor is not visible. I am kind of at a loss about how to go about this.

For the search, I suppose I'd use JS to set a hidden form variable with the supervisor's id, when the select a result? Or how do I store the supervisor value, so that it is set correctly on the Employee when submit is clicked?

Can someone point me in the right direction, I don't need a coded solution, but just an overview. I am using the free Telerik controls if that helps.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小墨 2024-12-14 00:34:31

是的,您可以使用只读文本框来保存该值。那里没问题。

Yes, you could use a read-only textbox to hold the value. No problem there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文