をいただければ幸い作ることができるか、誰かが私を伝えることができますので、もし、私はMVCで始まる理解いくつかの例を読んでいませんその後、
public class Author
{
public int IdAuthor { get; set; }
public bool Selected { get; set; }
public string Name { get; set; }
}
と::
public class HomeController : Controller
{
public ActionResult Index()
{
var book = new Book
{
IdBook = 1,
Title = "foo bar",
Authors = new[]
{
new Author { IdAuthor = 1, Name = "author 1" },
new Author { IdAuthor = 2, Name = "author 2" },
new Author { IdAuthor = 3, Name = "author 3" },
}.ToList()
};
return View(book);
}
[HttpPost]
public ActionResult Index(Book book)
{
return View(book);
}
}
とビューで:彼は与えられた書籍やないために選択したかどうかを
@model Book
@using (Html.BeginForm())
{
<div>
@Html.LabelFor(x => x.Title)
@Html.EditorFor(x => x.Title)
</div>
for (int i = 0; i < Model.Authors.Count; i++)
{
@Html.CheckBoxFor(x => x.Authors[i].Selected)
@Html.LabelFor(x => x.Authors[i].Selected, Model.Authors[i].Name)
@Html.HiddenFor(x => x.Authors[i].Name)
}
<p>
<button type="submit">OK</button>
</p>
}
この質問を見るhttp://stackoverflow.com/questions/4872192/checkboxlist-in-mvc3-0 – AyKarsi