基本的には、テキストボックス、ラジオボタン、およびチェックボックスコントロールを持つフォームがあります。今私は私のページ を提出したときに、私はこの他のフォームコントロールとのMVCフォームでのCheckBoxForの使用方法
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();
}
今私は私のアプリを実行したときに、私はすべての情報を取得する傾向があるが、私はページを送信する場合はnullが
公共一覧教育を{取得値と私は、このプロパティを取得します。セット; }
私が間違ってやっていることについてお手伝いできますか、これを達成する方法について正しい道に向けることができますか?
で説明したように、部分的に
HtmlFieldPrefix
を渡すことであろう、それはあなたに面白い聞こえるかもしれ@StephenMueckeが、私は本当に答えを受け入れる方法を知らない、私はいつも私を助ける答えに投票する:) 今私は答えを投票する方法を学ぶためにブログを通っています..ありがとう、私の質問を助けてください答えを知って –@StephenMueckeちょっと..あなたのフィードバックのためにありがとう私はついに答えを受け入れる方法を知っている必要があります...もう一度ありがとう、私の質問の答えを知っている場合私に知らせてください:) –