我有一個.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