我的视图页面中有几个复选框..
<div id ="rightPanelviewList">
<div class ="divCheck">
@Html.CheckBoxFor(model => model.IsChnView, new { id = "CHN"}) CHN
</div>
<div class ="divCheck">
@Html.CheckBoxFor(model => model.IsCMBView, new { id = "CMB"}) CMB
</div>
<div class ="divCheck">
@Html.CheckBoxFor(model => model.IsGermanyView, new { id = "Germany"}) Germany
</div>
<div class ="divCheck">
@Html.CheckBoxFor(model => model.IsHYDView, new { id = "HYD"}) HYD
</div>
<div class ="divCheck">
@Html.CheckBoxFor(model => model.IsSBUManagedServicesView, new { id = "SBUManagedServices"}) SBU: Managed Services
</div>
<div class ="divCheck">
@Html.CheckBoxFor(model => model.IsSBUSolutionsView, new { id = "SBUSolutions"}) SBU: Solutions
</div>
<div class ="divCheck">
@Html.CheckBoxFor(model => model.IsUSFSCView, new { id = "USFSC"}) US FSC
</div>
<div class ="divCheck">
@Html.CheckBoxFor(model => model.IsUSFTBView, new { id = "USFT"}) US FT
</div>
<div class ="divCheck">
@Html.CheckBoxFor(model => model.IsUSWindsorView, new { id = "USWindsor"}) US Windsor
</div>
</div>
使用 json 我试图获取选定的复选框 id,这是我的逻辑
$("#AllDimention").click(
function() {
if ($("#AllDimention").is(':checked')) {
$("#CHN").prop('checked', true);
$("#CMB").prop('checked', true);
$("#HYD").prop('checked', true);
$("#Germany").prop('checked', true);
}
var ViewNames = new Array();
var dict = []; // create an empty array
$('#rightPanelviewList input[type=checkbox]').each(function() {
var id = $(this).attr('id')
dict.push({
key: id,
value: $(this).attr('checked')
});
alert(JSON.stringify(dict))
});
$.ajax({
url: '@Url.Action("Manage", "Admin")',
type: 'POST',
datatype: "json",
traditional: true,
data: {
'ViewNames': JSON.stringify(dict)
},
success: function(result) {
alert(JSON.stringify(result));
}
});
});
当重定向到查看我收到错误..
“字符串为空”
这是我试图得到的模型
[HttpPost]
public ActionResult Manage(ListBoxViewModel model, string ViewNames)
{
if (model.User != null)
{ }
您能否在这个问题上帮助我或为这个问题提供其他替代方案。