There are 28 check boxes that are given a common name and have different values:
<input type="checkbox" name="Schedules" id="checkbox1" value="1">
In controller in post action:
public ActionResult Create(SubscriptionPlanCreateViewModel subscriptionPlanCreateViewModel, FormCollection Form)
{
string[] AllStrings = Form["Schedules"].Split(',');
foreach (string item in AllStrings)
{
int value = int.Parse(item);
if (value == 1)
{
subscriptionPlanCreateViewModel.Timeschedule = "OneTime";
}
}
}
By using this code I need to use 28 if
conditions. How can I reduce the code size?
if
conditions trying to set theTimeschedule
property? Or are they all setting different properties on your view model? Also, do you have any control over how the view is generated, or are you restricted to just changing the controller code? – StriplingWarrior Nov 15 '11 at 5:46