In the ViewModel:
SelectSafetyContacts = new SelectList(subcontractRepository.GetContacts(Subcontract.company_id), "contact_id", "contact_name", Subcontract.safety_contact);
In the Repository:
public IQueryable<contact> GetContacts(Guid id)
{
return
db.companies
.Where(c => c.active_status == true)
.Where(c => c.primary_company == id || c.company_id == id)
.SelectMany(ct => ct.contacts).Where(ct => ct.active_status == true);
}
In the form:
<%= Html.DropDownList("safety_contact", Model.SelectSafetyContacts, "** Select Contact **") %>
This works great except when in the form they change the company. The contacts need to then change to match the new company. I assume that I can somehow do this with jQuery, but I'm not sure how. Can I reference the GetContacts function in the Repository, so that in the future if an update to this select is made, it will only be in one place?