I have Controller that looks like this:
public class PollController : BaseController
{
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public Task<IActionResult> AddVotingRecord(VotingRecordBindingModel model)
{
throw new NotImplementedException();
}
}
My view is:
@model IEnumerable<SmartStoreNetCore.Web.Models.ViewModels.PollViewModel>
<div class="list-group-item text-muted title">COMMUNITY POLL</div>
@foreach (var poll in Model)
{
<form asp-controller="Poll" asp-action="AddVotingRecord" method="post">
<div class="list-group">
<div class="list-group-item title">@Html.Raw(poll.Name)</div>
@foreach (var pollAnswer in poll.PollAnswers)
{
<div class="list-group-item text-muted">
<input asp-for="@pollAnswer.VotingRecordBindingModel.PollAnswerId"
type="radio"
value="@pollAnswer.Id"/>
@Html.Raw(pollAnswer.Name)
</div>
}
<div class="list-group-item title">
<input class="btn btn-warning btnCustom" type="submit" value="VOTE"/>
</div>
</form>
}
Where PollViewModel
contains collection of PollAnswersViewModel
where is the VotingRecordBindingModel
which has property PollAnswerId
.
The code above generates the right HTML and the values are the corect ids.
I am getting the VotingRecordBindingModel
returned to the Controller but its property PollAnswerId
is always 0
.
I can't figure out what is going wrong.
EDIT:
I tried to add GET method AddVotingRecord()
that returns new VotingRecordBindingModel()
but without result.