请帮忙。
我有3张桌子
PublicationType
表包含columnsTypeID,description Quantities
表格包含quantityId,description Agent Publicationquantities
表包含columnsTypeID,quantityId 当用户选择Publication
下拉列表时,如何在MVC3中编写jQuery或Json,然后第二个下拉列表是数量
下拉列表将根据所选的Publication下拉列表填充(使用第三个表AgentPublicationQuantity检查)
示例如果用户选择发布id = 9测试发布3,则数量应填充一半,全部,一半和全部供用户选择。)
从目前为止在视图页面上的代码中,我有两个下拉列表:
PublicationType
填充出版物Quantity
填充数量列表我希望数量基于PublicationType下拉列表值填充,因为不同的发布具有不同的可用数量。
这是我的代码
public ActionResult Create(int agentID)
{
// Get data to display create page.
AgentPublicationOrder publication = new AgentPublicationOrder(); // Declare new instance of Agent Adjustment object.
AgentViewModel viewModel = new AgentViewModel(agentID, this.User.Identity.Name); // Create lightweight agent view model.
AgentPublicationOrderViewModel publicationviewmodel = new AgentPublicationOrderViewModel(agentID);
ViewBag.loggedInUserName = viewModel.loggedInUserName;
ViewBag.fullContactName = viewModel.fullContactName;
ViewBag.agentID = viewModel.agentID;
// get data to populate dropdowlist
using (var db1 = new AgentPublicationTypesDBContext())
{
var agentquantityFromDB = db1.AgentPublicationTypePublicationQuantities.Select(x => x.publicationQuantityId).ToList();
// dropdownlist pulicationType
ViewBag.AgentPublicationTypes = db1.AgentPublicationTypes.Where(x => agentquantityFromDB.Contains(x.id) && x.inactiveDate > DateTime.Today || !x.inactiveDate.HasValue).OrderBy(a => a.description).ToList();
//dropdownlist Quantity
ViewBag.Quantities = db1.PublicationQuantities.Where(x => agentquantityFromDB.Contains(x.id) || x.inactiveDate == null && x.inactiveDate > DateTime.Today).OrderBy(x => x.id).ToList();
}
return View(publication);
}
这是我的观看页面
<div class="three_column_row">
<div class="three_column_col">
<div class="labelCell2">
Publication:
</div>
<div class="editorCell">
@Html.DropDownListFor(model => model.agentPublicationTypeid, new SelectList(@ViewBag.AgentPublicationTypes, "id", "description", (Model.agentPublicationTypeid != 0 ? Model.agentPublicationTypeid : -1)), "--Select One--")
</div>
</div>
<div class="three_column_col">
<div class="labelCell2">
Qty:
</div>
<div class="editorCell">
@Html.DropDownListFor(model => model.quantityId, new SelectList(@ViewBag.Quantities, "id", "description"), "--Select One--")
</div>
</div>
</div>`