在視圖模型:更新下拉值
SelectSafetyContacts = new SelectList(subcontractRepository.GetContacts(Subcontract.company_id), "contact_id", "contact_name", Subcontract.safety_contact);
在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);
}
形式:
<%= Html.DropDownList("safety_contact", Model.SelectSafetyContacts, "** Select Contact **") %>
這當形式,他們改變,除了偉大工程的公司。聯繫人需要更改以匹配新公司。我認爲我可以以某種方式與jQuery做到這一點,但我不知道如何。我可以引用存儲庫中的GetContacts函數,以便將來如果對此選擇進行更新,它只會在一個位置?