我的视图页面中有几个复选框..
<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's,这是我的逻辑
$("#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));
}
});
});
重定向到查看时我收到错误..
“string is null”
这是我试图获得的模型
[HttpPost]
public ActionResult Manage(ListBoxViewModel model, string ViewNames)
{
if (model.User != null)
{ }
你可以帮我解决这个问题,或者为这个问题提供其他选择。