我进行了很多搜索,只花了 3 天时间来搜索和尝试不同的技术(在 stackoverflow 等上),但我没有找到在 asp.net mvc 中实现 checkboxlist 的解决方案。最后我将我的问题发布到stackoverflow;
所以,我的模型看起来像这样;
我的模型的多对多关系(1个类别可能包含许多项目,一个项目可能属于许多类别)
我的控制器;
[HttpGet]
[Authorize(Roles = "Admin")]
public ActionResult ProjectAdd()
{
return View();
}
我的观点;
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Add New Project</legend>
<div class="editor-label">
@Html.LabelFor(model => model.ProjectHeading)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProjectHeading)
@Html.ValidationMessageFor(model => model.ProjectHeading)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ProjecctUrl)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProjecctUrl)
@Html.ValidationMessageFor(model => model.ProjecctUrl)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ProjectLongDescription)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProjectLongDescription)
@Html.ValidationMessageFor(model => model.ProjectLongDescription)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.PromoFront)
</div>
@Html.EditorFor(model => model.PromoFront)
@Html.ValidationMessageFor(model => model.PromoFront)
<div class="editor-label">
@Html.LabelFor(model => model.ProjectThubmnail)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProjectThubmnail)
@Html.ValidationMessageFor(model => model.ProjectThubmnail)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ProjectImage)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProjectImage)
@Html.ValidationMessageFor(model => model.ProjectImage)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.CategoryId)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CategoryId)
@Html.ValidationMessageFor(model => model.CategoryId)
</div>
<p>
<input type="submit" value="Create" class="submit" />
</p>
所以,我的问题是如何在我的视图中显示类别的复选框列表?
如何从该复选框列表中获取选定的值?