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.
Yes, you could use a read-only textbox to hold the value. No problem there.