I made use of generic class as below
public class GenericPaymentMethod<T>
{
public int TenantID { get; set; }
public string Market { get; set; }
public List<T> CreditCard { get; set; }
public List<T> DebitCard { get; set; }
public List<T> BPay { get; set; }
}
public class PaymentMethod
{
public GenericPaymentMethod<string> MyProperty { get; set; }
}
public class EditPaymentMethod
{
public GenericPaymentMethod<Multicheckbox> MyProperty { get; set; }
}
And in model I accessed in following way
public static EditPaymentMethod GetPaymentMethodDetails(int tenantID) {
EditPaymentMethod obj = new EditPaymentMethod();
obj.MyProperty = new GenericPaymentMethod<Multicheckbox>();
obj.MyProperty.TenantID = 1000;
obj.MyProperty.Market = "AU";
obj.MyProperty.CreditCard = new List<Multicheckbox>(){
new Multicheckbox { CheckboxName = "Amex", IsChecked = true },
new Multicheckbox { CheckboxName = "Master Card", IsChecked = false },
new Multicheckbox { CheckboxName = "Visa", IsChecked = true }
};
obj.MyProperty.DebitCard = new List<Multicheckbox>(){
new Multicheckbox { CheckboxName = "Amex", IsChecked = false },
new Multicheckbox { CheckboxName = "Master Card", IsChecked = true },
new Multicheckbox { CheckboxName = "Visa", IsChecked = false }
};
obj.MyProperty.BPay = new List<Multicheckbox>(){
new Multicheckbox { CheckboxName = "Savings Cheque", IsChecked = true },
new Multicheckbox { CheckboxName = "Credit Card", IsChecked = false },
};
return obj;
}
And in View
<div>
<div>
@Html.Label("Debit Card :")
</div>
@for (int i = 0; i < Model.MyProperty.DebitCard.Count; i++)
{
<div>
<div>
@Html.CheckBoxFor(x => x.MyProperty.DebitCard[i].IsChecked)
</div>
<div>
@Model.MyProperty.DebitCard[i].CheckboxName
@Html.HiddenFor(x => Model.MyProperty.DebitCard[i].CheckboxName)
</div>
</div>
}
@Html.HiddenFor(model => Model.AtleastOneDebitCardSelected)
@Html.ValidationMessageFor(model => Model.AtleastOneDebitCardSelected)
</div>