如何将多选列中的值从视图传递到控制器Get方法。我尝试将值从dropdownDepot传递到控制器参数列表部门。请帮帮忙
public class ReportViewModel
{
public int DepotNo { get; set; }
public List<int> Department { get; set; }
}
[HttpGet]
public IActionResult EmployeeView(ReportViewModel report, List<int> Department,int DepotNo = 0)
{
List<EmployeeWorkTimeSettingsModel> log = new List<EmployeeWorkTimeSettingsModel>();
log = ReportService.GetDepotEmployeeWorkHrsReport(connectionSettings, (HttpContext.Session.GetInt32("UserID") ?? 0).ToString(),
String.Join(",", report.DepotNo), String.Join(",", report.Department));
ViewBag.EmpviewReport = log;
}
<div class="controls col-sm-9">
<select asp-for="DepotNo" class="form-control" id="dropdownDepot" asp-items="@ViewBag.UserDepots" onchange="FillEmployee()" data-role="select"></select>
<span asp-validation-for="DepotNo" class="text-danger"></span>
</div>
<div class="controls col-sm-9">
<select id="dropdownDepartment" class="form-control" asp-for="Department" asp-items="@ViewBag.UserDepartments" onchange="FillEmployee()"
data-role="select"></select>
</div>
$('#dropdownDepartment').multiselect({
columns: 1,
placeholder: 'Select Department',
includeSelectAllOption: true,
maxHeight: 300
});
function FillEmployee() {
var href = '/Report/EmployeeView?depot=' + $("#dropdownDepot option:selected").val() + '&department=' + Get the Value from multiselect departments;
$("#lnkFilter").attr('href', href);
$("#lnkFilter").click();
}
发布于 2019-03-04 21:37:04
您可以直接在select元素上使用val()
,而不必先按选定的选项进行过滤。当您对select multiple执行此操作时,将返回一个由选定值组成的数组:
$('#dropdownDepot').val() // single selected value
和
$('dropdownDepartment').val() // array of selected values
为了正确绑定数组,您需要为每个选定的值实际重复department
参数:
&department=value1&department=value2&department=value3
下面这样的代码应该可以解决这个问题:
'&department=' + $('#dropdownDepartment').val().join('&department=')
https://stackoverflow.com/questions/54983860
复制相似问题