@model Chechbox_List_MVC.Models.checkbox_Master
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>How to bind CheckBoxList in MVC </title>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
</head>
<body>
<div>
<div class="col-md-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2><small>CheckBox List Bind</small></h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
@using (Html.BeginForm("", "Checkbox_List", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.role_Database, "Checkbox bind from Database", htmlAttributes: new { @class = "control-label col-md-3 col-sm-3 col-xs-12" })
<div class="col-md-6 col-sm-9 -xs-12">
@for (int i = 0; i < Model.checkDatabase.Count(); i++)
{
@Html.CheckBoxFor(m => m.checkDatabase[i].Selected, new { @class = "flat" })@Model.checkDatabase[i].Text
@Html.HiddenFor(m => m.checkDatabase[i].Text)
@Html.HiddenFor(m => m.checkDatabase[1].Value)
}
@Html.ValidationMessageFor(model => model.role_Database, "", new { @class = "text-danger" })
</div>
</div>
<br />
<br />
<div class="form-group">
@Html.LabelFor(model => model.role_Static, "Checkbox bind from static list of items", htmlAttributes: new { @class = "control-label col-md-3 col-sm-3 col-xs-12" })
<div class="col-md-6 col-sm-9 -xs-12">
@for (int i = 0; i < Model.StaticCheckbox.Count(); i++)
{
@Html.CheckBoxFor(m => m.StaticCheckbox[i].Selected, new { @class = "flat" })
@Html.DisplayFor(m => m.StaticCheckbox[i].Text)
@Html.HiddenFor(m => m.StaticCheckbox[1].Value)
}
@Html.ValidationMessageFor(model => model.role_Database, "", new { @class = "text-danger" })
</div>
</div>
<br />
<br />
<div class="form-group">
<b>@Html.LabelFor(model => model.Selected_Result, "OutPut", htmlAttributes: new { @class = "control-label col-md-3 col-sm-3 col-xs-12" }) </b>
<div class="col-md-6 col-sm-9 col-xs-12">
@Html.DisplayFor(model => model.Selected_Result, new { htmlAttributes = new { @class = "form-control", @Type = "email" } })
@Html.ValidationMessageFor(model => model.Selected_Result, "", new { @class = "text-danger" })
</div>
</div>
<br />
<br />
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-sm-9 col-xs-12 col-md-offset-3">
<button type="button" class="btn btn-primary">Cancel</button>
<button type="reset" class="btn btn-primary">Reset</button>
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</div>
}
</div>
</div>
</div>
</div>
</body>
</html>