[英]I want to do a multiple selector with checkboxes in ASP.NET MVC it fetches the employee ID from a Sql database
<label asp-for="EmployeeId" class="control-label"></label>
@Html.DropDownListFor(m => m.EmployeeId, (SelectList)ViewBag.LineManager, "Select",
new { @class = "form-control", multiple = "multiple"})
@Html.ValidationMessageFor(model => model.EmployeeId, "", new { @class = "text-danger" })
</div>
'''''''''My Controller Looks Like this'''''''''' My controller handles the brings back the information i have on the datebase of which its all the names of the employees i have created ''''''''我的 Controller 看起来像这样
string uri = "Vfl";字符串 uri = "Vfl";
var searchValue = HttpContext.Request.Form["search[value]"].FirstOrDefault();
var start = Request.Form["start"].FirstOrDefault();
// Paging Length 10,20
var length = Request.Form["length"].FirstOrDefault();
int pageSize = length != null ? Convert.ToInt32(length) : 0;
int skip = start != null ? Convert.ToInt32(start) : 0;
int recordsTotal = 0;
var response = _vflService.GetAll(uri, "");
foreach(var item in response)
{
item.EmployeeName = GetEmployeeName(item.ReponsiblePersonId);
}
//Search
if (!string.IsNullOrEmpty(searchValue))
{
response = response.Where(m => m.EmployeeName.ToLower().Contains(searchValue.ToLower()) || (!string.IsNullOrEmpty(m.ImmediateCauseDescription) && m.ImmediateCauseDescription.ToLower().Contains(searchValue.ToLower())));
}
recordsTotal = response.Count();
//Paging
var data = response.Skip(skip).Take(pageSize).ToList();
return Json(new { recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data });
You should be using a MultiSelectList - https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.rendering.multiselectlist?view=aspnetcore-5.0您应该使用 MultiSelectList - https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.rendering.multiselectlist?view=aspnetcore-5.0
Try using尝试使用
@Html.DropDownListFor(m => m.EmployeeId, (SelectList)ViewBag.LineManager, "Select", new { @class = "form-control",multiple = "multiple", size = "5" })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.