I am trying to create radio button groups that correspond to a "registration". Each registration can have multiple "payment options" I need to be able to select an option for each registration then pass those values to the controller. I have looked at the solutions and the comments from yesterday and this is my updated code but its still not working.
<div id="regsAndFees">
<ol>
@foreach (var reg in Model.PendingRegistrations.Cart)
{
<li>
<label>@reg.Description - </label> <span><label>@reg.Fee.ToString("C")</label></span>
<ul style="list-style:none;">
@foreach (var fee in reg.AdditionalFees)
{
<li>
<label>@fee.AdditionalFee.ToString("C")</label>
<span>@fee.Description</span>
</li>
}
</ul>
@for (int i = 0; i < Model.PaymentOptions.RegistrationPaymentTypes.Count; i++)
{
@Html.RadioButtonFor(m => m.PaymentOptions.RegistrationPaymentTypes[i], @Model.PendingRegistrations.PaymentOptions.RegistrationPaymentTypes)
@Html.LabelFor(m => m.PaymentOptions.RegistrationPaymentTypes[i], @Model.PendingRegistrations.PaymentOptions.RegistrationPaymentTypes)
<br />
}
</li>
}
</ol>
</div
Models
public class ViewModelPendingRegistrations
{
public ViewModelPendingRegistrations()
{
PendingRegistrations = new List<ViewModelPendingRegistration>();
Errors = new List<string>();
this.TempCart = new List<SalesTax.TempCart>();
this.Cart = new List<Registrations.Cart>();
this.PaymentOptions = new ViewModelPaymentOptions();
}
public ViewModelPaymentOptions PaymentOptions { get; set; }
public List<Domain.ViewModel.Registrations.Cart> Cart { get; set; }
public List<ViewModelPendingRegistration> PendingRegistrations { get; set; }
public bool IsBusinessAdmin { get; set; }
public bool HasBusinessRegistrations { get; set; }
public bool HasIndividualRegistrations { get; set; }
public List<string> Errors { get; set; }
here is Model.PendingRegistrations.Cart
public class Cart
{
public Cart()
{
this.AdditionalFees = new List<ViewModelAdditionalFee>();
this.PaymentOptions = new ViewModelPaymentOptions();
}
public List<ViewModelRegistrationRequirement> Requirements { get; set; }
public ViewModelPaymentOptions PaymentOptions { get; set; }
public int SelectedPaymentOption { get; set; }
public string EntityName { get; set; }
}
this is my controller method
public ActionResult PaymentOptions(Domain.ViewModel.PaymentModel model)
{
var pendingRegistrations = new BusinessLayer.Registration().GetPendingRegistrations(false, false, AppUser.UserId, true);
var paymentdetails = new BusinessLayer.PaymentType().GetAllActive();
var regs = pendingRegistrations.Cart;
model.PendingRegistrations.Cart = regs;
var payments = new BusinessLayer.RegistrationTypePaymentType().GetAll();
foreach (var pendingReg in regs)
{
model.PaymentOptions.RegistrationPaymentTypes = payments.Where(x => x.RegistrationTypeID == pendingReg.RegistrationTypeID).ToList();
foreach (var pmt in pendingReg.PaymentOptions.RegistrationPaymentTypes)
{
var pmtnames = paymentdetails.Where(x => x.PaymentTypeID == pmt.PaymentTypeID).FirstOrDefault();
pmt.PaymentName = pmtnames.Name;
}
}
return View(model);
}