以下是我
的相关内容视图模型:
[Display(Name = "One Per Line")]
public bool OnePerLine { get; set; }
[Display(Name = "Comma Separated")]
public bool CommaSeparated { get; set; }
[Display(Name="Upper Case")]
public bool UpperCase { get; set; }
查看:
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "form-horizontal" }))
{
.
.
<div class="control-group">
@Html.LabelFor(m => m.OnePerLine, "One Per Line?", new Dictionary<string, object> { { "class", "control-label" } })
<div class="controls">
@Html.CheckBoxFor(m => m.OnePerLine)
</div>
</div>
<div class="control-group">
@Html.LabelFor(m => m.CommaSeparated, "Comma separate them?", new Dictionary<string, object> { { "class", "control-label" } })
<div class="controls">
@Html.CheckBoxFor(m => m.CommaSeparated)
</div>
</div>
<div class="control-group">
@Html.LabelFor(m => m.UpperCase, "Uppercase?", new Dictionary<string, object> { { "class", "control-label" } })
<div class="controls">
@Html.CheckBoxFor(m => m.UpperCase)
</div>
</div>
.
.
}
这就是我在帖子中看到的提琴手:
OnePerLine=true&OnePerLine=false&CommaSeparated=true&CommaSeparated=false&UpperCase=true&UpperCase=false
当它到达我的控制器时,viewmodel从视图中获得了正确的值,我发现在帖子体中加倍奇数。