我在其中一种形式中使用多个 select2。提交表单后,在后端,仅获取单个选定值,而选择多个选项。
HTML
<form id="test" method="POST">
<select name="dps_days_to[NL]" class="dokan-form-control dps_days_selection" required multiple="multiple">
<option></option>
<option value="0">Sunday</option>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thurday</option>
</select>
</form>
Run Code Online (Sandbox Code Playgroud)
JS
jQuery(document).ready(function( $ ){
jQuery('.dps_days_selection').select2({
placeholder: "Please select a day"
});
});
Run Code Online (Sandbox Code Playgroud)
PHP
var_dump($_POST['dps_days_to']);
Run Code Online (Sandbox Code Playgroud)
结果
Array
(
[0] => 1
)
Run Code Online (Sandbox Code Playgroud)
例如:如果从 select2 multiple 下拉列表中的可用选项中选择了 Sunday & Monday,则只返回 options Monday 的值(即 1)
拜托,有人可以帮我吗?
有没有办法将字符串参数和列表返回给c#中的方法?
List<cCountry> countries = new List<cCountry>();
countries = GetCountries(userProfile.Country);
private List<cCountry> GetCountries(string p)
{
inputCollection = new cDTOCollection<cDTOBase>();
outputCollection = new cDTOCollection<cDTOBase>();
outputCollection = UpdateProfileBizobj.ProcessRequest(ActionConstants.ActionGetCountriesList, null);
List<cCountry> countries = new List<cCountry>();
cDTOSingleValue SelectedCountryID = new cDTOSingleValue();
foreach (cDTOCountry countryItem in outputCollection)
{
if (p == countryItem.CountryName)
SelectedCountryID.Id = countryItem.CountryID;
countries.Add(Mapper.Map<cDTOCountry, cCountry>(countryItem));
}
countries.Remove(countries[0]);
return countries;
}
Run Code Online (Sandbox Code Playgroud)
就像上面的方法一样,我需要返回一个参数SelectedCountryID以及国家列表.有没有办法返回两者?