我有一个.NET MVC应用程序。我正在尝试使用jquery ajax将数据发布到我的控制器。似乎一切工作基于查看Firebug控制台(我可以在我的发布请求中看到数组中的值),但在控制器中,IEnumerable STRMSelected为null。任何想法,我在做什么错?通过jquery/ajax将控制器的复选框值传递给控制器
局部视图
@if (Model.Count() > 0)
{
foreach (var item in Model)
{
//int countAU = 1, countSP = 1, countSU = 1;
string nameAU = "AU" + @item.year;
string nameSP = "SP" + @item.year;
string nameSU = "SU" + @item.year;
<tr>
<td style="text-align:center;">
<strong><label> @item.year</label></strong>
</td>
<td style="text-align:center;">
@if (@item.AU != null)
{
<input type="checkbox" [email protected] id="@nameAU" value="@item.AU" />
//countAU++;
}
else
{
<input type="checkbox" name="AUNonex" id="AUNone" disabled />
}
</td>
</tr>
}
}
主视图
<div class="gradfacapp-samerow">
<input type="submit" value="Save Request for Later" name="action:Save" class="cancel" />
<input type="submit" value="Submit Request" id="submit" name="action:Submit" onclick="javascript:return checkSubmit();" />
</div>
<script>
$('#submit').on('click', function() {
var STRMS = [];
$('input:checked').each(function() {
STRMS.push($(this).attr("value"));
});
$.ajax({
type: "POST",
url: '@Url.Action("Submit", "FeeAuth")',
dataType: "html",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ STRMSelected: STRMS }),
success:
function (data) { }
});
});
</script>
控制器
[HttpPost]
[MultipleButton(Name = "action", Argument = "Submit")]
public ActionResult Submit(FA fee, HttpPostedFileBase upfile, IEnumerable<string> STRMSelected)
{
code is here
}
我删除数据:数据,但它仍然在控制器中显示为空。我添加了Firebug的帖子截图。 – user2448412
尝试将STRMSelected输入更改为字符串,然后在控制器中对其进行反序列化以获得所需的特定值 – Simon