DropDownListFor傳引數

caoguanghui0804發表於2020-12-22

下面展示一些 內聯程式碼片

    <td class="table-dataCol">
                        @Html.Kendo().DropDownListFor(m => m.CustodyPeopleDepartmentID).BindTo(Model.DepartmentList).Value(Model.CustodyPeopleDepartmentID.ToString()).Events(e => { e.Change("changeCustody"); })
                        <br /><br />
                        @(Html.Kendo().DropDownListFor(m => m.CustodyPeopleId)
                                            .DataTextField("Text")
                                            .DataValueField("Value")
                                            .DataSource(dataSource => dataSource
                                                .Read(read => read.Action("GetAccountSelectList", Html.ControllerName()).Type(HttpVerbs.Post).Data("getCustodyDepartmentId"))
                                             ).Value(Model.CustodyPeopleId.ToString())
                                             .Events(e => e.DataBound("dataBound"))
                        )
                        @Html.ValidationMessageFor(m => m.CustodyPeopleId)
                    </td>
  function getCustodyDepartmentId() {
        return {
            departmentId: $("#CustodyPeopleDepartmentID").val()
        };
    }

    public ActionResult GetAccountSelectList(decimal departmentId)
        {
            if (departmentId == 0) return HttpNotFound();
            return Json(new MachineHandler().GetAccountSelectList(departmentId));
        }
   // 系統帳號
        public List<SelectListItem> GetAccountSelectList(decimal? departmentId = null)
        {
            var list = db.ACCOUNT.AsQueryable();
            if (departmentId != null) list = list.Where(x => x.DEPARTMENTID == departmentId);
            return list.Select(x => new SelectListItem() { Text = x.NAME, Value = x.ID.ToString() }).ToList();
        }

相關文章