javascript当选择第一个下拉列表时,第二个下拉列表将根据第一个下拉列表值填充

时间:2014-11-17 14:58:05

标签: javascript c# jquery html asp.net-mvc

请帮忙。

我有3张桌子

  1. PublicationType表包含columnsTypeID,description
  2. Quantities表格包含quantityId,description
  3. Agent Publicationquantities表包含columnsTypeID,quantityId
  4. 当用户选择Publication下拉列表时,如何在MVC3中编写jQuery或Json,然后第二个下拉列表是数量

    下拉列表将根据所选的Publication下拉列表填充(使用第三个表AgentPublicationQuantity检查)

    示例如果用户选择发布id = 9测试发布3,则数量应填充一半,全部,一半和全部供用户选择。)

    从目前为止在视图页面上的代码中,我有两个下拉列表:

    1. PublicationType填充出版物
    2. Quantity填充数量列表
    3. 我希望数量基于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>`
      

0 个答案:

没有答案