【发布时间】:2016-08-21 20:25:13
【问题描述】:
基本上,我有一个带有文本框、单选按钮和复选框控件的表单。现在我在提交页面时遇到复选框控件的问题 我有一个这样的模型
public class PersonDetails
{
public int personID { get; set; }
public string PersonName { get; set; }
public string Gender { get; set; }
public List<Education> Education { get; set; }
public string EmailID { get; set; }
public string Address { get; set; }
}
public class Education
{
public string Qualification { get; set; }
public bool Checked { get; set; }
public List<Education> GetQualification()
{
return new List<Education>{
new Education {Qualification="SSC",Checked=false},
new Education {Qualification="HSC",Checked=false},
new Education {Qualification="Graduation",Checked=false},
new Education {Qualification="PostGraduation",Checked=false}
};
}
}
我有这样的看法
@using (Html.BeginForm("GetDetails", "User", FormMethod.Post, new { id = "person-form" }))
{
<div class="col-xs-12">
<label>Person Name</label>
@Html.TextBoxFor(x => x.PersonName)
</div>
<div class="col-xs-12">
<label>Gender</label>
@Html.RadioButtonFor(x => x.Gender, "Male")
@Html.RadioButtonFor(x => x.Gender, "Female")
</div>
<div class="col-xs-12">
<label>Education</label>
@{
Html.RenderPartial("Qualification", new LearnAuthentication.Controllers.Education().GetQualification());
}
</div>
<div class="col-xs-12">
<input type="submit" value="Submit" />
</div>
}
还有这样的局部视图
@model List<LearnAuthentication.Controllers.Education>
<br />
@for (int i = 0; i < Model.Count(); i++)
{
@Html.HiddenFor(x => Model[i].Qualification)
@Html.CheckBoxFor(x => Model[i].Checked)
@Html.DisplayFor(x => Model[i].Qualification)
<br />
}
我的操作方法是这样的
[HttpPost]
public ActionResult GetDetails(PersonDetails personDetails)
{
return View();
}
现在,当我运行我的应用程序时,我倾向于获取所有信息,但是当我提交页面时,我得到了这个带有空值的属性
公开名单教育{得到;放; }
你们中的任何人都可以帮助我解决我做错了什么吗,或者你能指导我如何实现这一目标的正确道路。
【问题讨论】:
-
@StephenMuecke 这对你来说可能听起来很有趣,但我真的不知道如何接受答案,作为一种感谢,我总是投票给对我有帮助的答案:) 现在我正在浏览博客来学习如何投票给答案.. 谢谢,如果你知道答案,请帮助我的问题
-
@StephenMuecke 嘿……谢谢您的反馈,我终于知道如何接受答案了……再次感谢您,如果您知道我的问题的答案,请告诉我 :)