I have a .NET MVC application. I am attempting to post data to my controller using jquery ajax. Everything seems to be working based on viewing the Firebug console (I can see the values in an array in my post request) but in the controller I am getting null for IEnumerable STRMSelected. Any ideas on what I am doing wrong??
partial view
@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" name=@nameAU id="@nameAU" value="@item.AU" />
//countAU++;
}
else
{
<input type="checkbox" name="AUNonex" id="AUNone" disabled />
}
</td>
</tr>
}
}
Main View
<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>
Controller
[HttpPost]
[MultipleButton(Name = "action", Argument = "Submit")]
public ActionResult Submit(FA fee, HttpPostedFileBase upfile, IEnumerable<string> STRMSelected)
{
code is here
}