So I'm new to MVC and ASP.Net. I've been reading through the posts on here all afternoon and I just can't get this to work. I have tried this, this, and this and I just don't know what I'm doing wrong.
Condition Class
public class conditions
{
public string condName;
public bool condValue;
public conditions(string s)
{
condName = s;
}
}
Risk History Class
public class riskHistory
{
public List<conditions> results;
public riskHistory()
{
results = new List<conditions>();
results.Add(new conditions("History of Marfans Syndrome"));
results.Add(new conditions("Family history of aortic disease"));
results.Add(new conditions("Recent aortic manipulation"));
results.Add(new conditions("Known thorasic aorta aneurysm"));
}
}
Now there is a riskPain and riskFeatures class defined the same way. I needed to split this into 3 because each has to be handled differently. What I display over each class unique in the view.
View Model defined as
public class adViewModel
{
public riskFeatures rF;
public riskPain rP;
public riskHistory rH;
public adViewModel()
{
rF = new riskFeatures();
rH = new riskHistory();
rP = new riskPain();
}
}
And then I have this code in the view. It's strongly typed to adViewModel.
Does the patient have any of the following history?
@for (int x =0; x<Model.rH.results.Count; x++)
{
string n = Model.rH.results[x].condName.ToString();
<b>@Html.Label(n)</b> @Html.CheckBoxFor(m => m.rH.results[x].condValue)
}
Does the patient have any of the following features to their pain?
// continue on to the other classes
The view displays correctly but when I submit the form it doesn't bind (all condvalue's are false). If you are going to suggest an editor template then I have a second question. The question in the view code above the for loop "Does the patient have the following history?" that question has to be different for each set of checkboxes. How would that work?
Thanks a ton guys! ~Chad