简体   繁体   English

我想在 ASP.NET MVC 中使用复选框做一个多重选择器,它从 Sql 数据库中获取员工 ID

[英]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 });

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.

相关问题 我想在 ASP.NET Core MVC 上显示视频 SQL 数据库视图 - I want to Show Video on ASP.NET Core MVC View from SQL Database ASP.NET MVC和具有多个属性的多个复选框,该怎么做? - ASP.NET MVC and multiple checkboxes for several properties, how to do that? 如何从ASP.NET MVC中的SQL Server数据库向多个收件人发送电子邮件? - How can I send email to multiple recipients from SQL Server database in ASP.NET MVC? 如何以列表形式从数据库中检索文本(SQL Server和ASP.NET MVC) - How do I retrieve text from database in list form (SQL Server & ASP.NET MVC) ASP.NET MVC多个复选框 - ASP.NET MVC Multiple Checkboxes 我想使用asp.net mvc 5将一个表中的ID保存到另一个表中 - I want to save an ID from a table to another table using asp.net mvc 5 (C#) 如何将图像文件从 ASP.NET MVC 5 web 表单发送到我的 SQL 数据库? - (C#) How do I send an image file from an ASP.NET MVC 5 web form to my SQL database? 我想根据用户ID将数据从SQL Server显示到ASP.NET文本框 - I want to display data from SQL Server to an ASP.NET textbox based on session of users id 如何将 ID 传递给 ASP.NET MVC 中的控制器? - How do I pass an ID to the controller in ASP.NET MVC? 如何在ASP.NET MVC中允许/ Controller / Id? - How do I allow /Controller/Id in ASP.NET MVC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM