所以我是MVC和ASP.Net的新手。我整个下午都在阅读这里的帖子,我无法得到这个工作。我试过this,this和this,我只是不知道我在做什么错。Checkboxfor not binding model
条件类
public class conditions
{
public string condName;
public bool condValue;
public conditions(string s)
{
condName = s;
}
}
风险历史课
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"));
}
}
现在有定义的相同方式riskPain和riskFeatures类。我需要将它分成3个,因为每个都必须以不同的方式处理。我在视图中显示每个独特类的内容。
视图模型定义为
public class adViewModel
{
public riskFeatures rF;
public riskPain rP;
public riskHistory rH;
public adViewModel()
{
rF = new riskFeatures();
rH = new riskHistory();
rP = new riskPain();
}
}
然后我在视图中该代码。这是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?
//继续到其他类
的视图显示正确的,但是当我提交表单它不绑定(所有condvalue的都是假的)。如果你要建议编辑模板,那么我还有第二个问题。在for循环的视图代码中的问题“患者是否有以下病史?”对于每组复选框,该问题必须有所不同。这将如何工作?
谢谢吨家伙! 〜Chad
您的控制器方法是用[HttpPost]修饰的方式提交的?此外,我建议你使用JavaScript与复选框显示某些问题。 – AwDogsGo2Heaven