如果未选择下拉菜单,如何设置默认值(多重选择)

时间:2019-01-25 07:05:21

标签: c# jquery asp.net-mvc

我使用剃刀语法,如果未选择下拉菜单或下拉文本为“选择一个”,我想将值设置为= 0 而且我有多个下拉菜单。并且我通过表单集合获取了此值

  @Html.DropDownListFor(model => item.JobStaffId, (SelectList)newSelectStaffList,new { @class = "form-control js-select js-noFilter hidden DDStaff DD2 ",multiple="multiple", size = "2", Id = "JobStaffId" + t })

enter image description here

 SelectList newSelectList = new SelectList((from s in Model.UserMasterList
                             .ToList()
                                                                   select new
                                                                   {
                                                                       userId = s.userId,
                                                                       userName =  (s.userFirstName +' '+  s.userLastName)
                                                                   }).Distinct()
                                                                   ,
                             "userId",
                             "userName",
                             string.IsNullOrEmpty(item.JobConstructionManagerId.ToString()) ? 0 : item.JobConstructionManagerId);  

1 个答案:

答案 0 :(得分:1)

您可以执行以下操作:

<form action="..." method="post">...</form>