I am having a slight issue sending checked grouped radio data to my controller action method in MVC
My View
@model IDictionary<int, List<ElectronicVotingSystem.ViewModels.VoteViewModel>>
@using (Html.BeginForm("ProcessVote", "Voter", FormMethod.Post, new { Id = "VoteForm" }))
{
foreach (var group in Model)
{
var name = group.Value.Where(m => m.Precedence == group.Key).Select(m => m.PositionName).FirstOrDefault();
<fieldset style="padding: 0 10px 0 10px" class="text-center">
<legend id="head">@name</legend>
<div class="row">
@foreach (var item in group.Value)
{
<div class="col-sm-4" style="margin-left: 50px">
<div class="row">
<div class="col-sm-12">
<img src="~/Aspirant/RetrieveImage/@item.Id" alt="Passport Picture" height=200 width=300 />
</div>
</div>
<div class="row">
<div class="col-sm-12 text-center">
<span style="font-weight: bold; font-size: 18px" id="applicant-name">@item.FirstName @item.MiddleName @item.Surname</span>
</div>
<div class="col-sm-12">
@Html.RadioButton(item.PositionName, item.Id)
</div>
</div>
</div>
}
</div>
</fieldset>
}
<button id="SubmitForm" type="submit" class="btn btn-primary" style="margin-right: 35%">Submit form</button>
}
My Controller
[HttpPost]
public ActionResult ProcessVote(IDictionary<int, List<VoteViewModel>> voteViewModel)
{
return View();
}
When I post to the action, I get Specified cast is not valid.
error.
Can someone help me on how to post values of the checked radio button groups to the controller?
Thanks in advance.