@model dynamic
@{
ViewBag.Title = "Documentation";
}
<div class="col_12">
<h3>@ViewBag.Title</h3>
@Html.Partial("GivenPartial")
<section>
<title>Base overloads</title>
<p>
<h6>Base checkbox list call structure:</h6>
<pre style="width: 45%;" class="content_left">
@Html.CheckBoxList("LIST_NAME",
model => model.LIST_DATA,
entity => entity.VALUE,
entity => entity.NAME,
model => model.SELECTED_VALUES)
// or entity => entity.IS_CHECKED
</pre>
<div class="margin_left17 margin_top40 content_left"><h6>OR</h6></div>
<pre style="width: 45%;" class="content_right">
@Html.CheckBoxListFor(model => model.LIST_NAME,
model => model.LIST_DATA,
entity => entity.VALUE,
entity => entity.NAME,
model => model.SELECTED_VALUES)
// or entity => entity.IS_CHECKED
</pre>
<div class="clear"></div>
</p>
<p>
<h6>And in our example it looks like this:</h6>
<pre>
@Html.CheckBoxListFor(model => model.PostedCities.CityIDs,
model => model.AvailableCities,
entity => entity.Id,
entity => entity.Name,
model => model.SelectedCities)
</pre>
</p>
<p>
<h6>Or if using boolean selector:</h6>
<pre>
@Html.CheckBoxListFor(model => model.PostedCities.CityIDs,
model => model.AvailableCities,
entity => entity.Id,
entity => entity.Name,
entity => entity.IsSelected)
</pre>
where <code>entity.IsSelected</code> is a boolean value from database
</p>
<p>
<h6>And another way to use boolean selector:</h6>
If we have a list of selected values on our View -
<code>var selectedIds = new List<int> { 1, 3, 5 };</code>
it'll look like this:
<pre>
@Html.CheckBoxListFor(model => model.PostedCities.CityIDs,
model => model.AvailableCities,
entity => entity.Id,
entity => entity.Name,
entity => selectedIds.Contains(entity.Id))
</pre>
where <code>selectedIds.Contains(entity.Id)</code> returns bool if item Id matches the list
</p>
</section>
<section>
<title>Basic Settings</title>
<p>
Since five base properties don't change, only extra ones will be shown, so placeholder
<code>...</code> means usage of five base properties
</p>
<p>
You might need to add this reference to your view first (namespace for <code>Position</code> <strong>enum</strong> and others):
<pre>@using MvcCheckBoxList.Model</pre>
</p>
<p>
<h6>1. Set position (direction) of the list:</h6>
<pre>@Html.CheckBoxListFor( ... , Position.Horizontal)</pre>
</p>
<p>
<code>Position</code> Can be <code>Position.Horizontal</code>, <code>Position.Vertical</code>,
<code>Position.Horizontal_RightToLeft</code>, or <code>Position.Vertical_RightToLeft</code>
where last two are to reverse checkbox and label for right-to-left languages
</p>
<p>
<h6>2. Set html attributes for both checkbox and label:</h6>
<pre>@Html.CheckBoxListFor( ... , x => new { @class="class_name" }) // Tags will be applied to all checkbox/label combos</pre>
or get Tags object from database:
<pre>@Html.CheckBoxListFor( ... , x => x.Tags) // x.Tags will be applied only to particular checkbox/label combo</pre>
</p>
<p>
<h6>3. Set html attributes and position:</h6>
<pre>@Html.CheckBoxListFor( ... , Position.Horizontal, x => new { @class="class_name" })</pre>
</p>
<p>
<h6>4. Set html attributes for all, disabled values, position, and individual html attributes (all attributes will be merged together):</h6>
<pre>@Html.CheckBoxListFor( ... , x => new { @class="class_name" }, new[] {"3", "5", "7"}, Position.Horizontal, x => x.Tags)</pre>
</p>
</section>
<section>
<title>Advanced Settings</title>
<p>
You might need to add this reference to your view first (namespace for <code>HtmlListInfo</code> <strong>class</strong> and others):
<pre>@using MvcCheckBoxList.Model</pre>
</p>
<p>
<h6>1. Set custom layout using <code>HtmlListInfo</code> class:</h6>
<pre>
var htmlListInfo = new HtmlListInfo(HtmlTag.table, 2, new { @class="class_name" }, TextLayout.Default, TemplateIsUsed.Yes);
@Html.CheckBoxListFor( ... , htmlListInfo)
</pre>
</p>
<p>
There, in <code>HtmlListInfo</code> class, <code>HtmlTag</code> can be
<code>HtmlTag.table</code> or <code>HtmlTag.vertical_columns</code>;
<code>2</code> is a number of columns;
</p>
<p>
<code>TextLayout</code> can be <code>TextLayout.Default</code>
or <code>TextLayout.RightToLeft</code> (for right to left languages)
</p>
<p>
<h6>2. Set layout with <code>HtmlListInfo</code> class and set html attributes:</h6>
<pre>
@Html.CheckBoxListFor( ... , htmlListInfo, x => new { tagName = "tagValue" }) // Tags will be applied to all checkbox/label combos
</pre>
or get Tags object from database:
<pre>
@Html.CheckBoxListFor( ... , htmlListInfo, x => x.Tags }) // x.Tags will be applied only to particular checkbox/label combo
</pre>
</p>
<p>
<h6>
3. Set html attributes for all, set layout with <code>HtmlListInfo</code>,
set disabled values, and individual html attributes (all attributes will be merged together):
</h6>
<pre>
@Html.CheckBoxListFor( ... , new { @class="class_name" }, htmlListInfo, new[] {"3", "5", "7"}, x => x.Tags)
</pre>
There, <code>x.Tags</code> is a value of type <code>object</code> and should be
equal to something similar to this <code>new { tag1 = "value1", tag2="value2" }</code>
and represent one or more custom html attributes, and will be applied to both
checkbox and label
</p>
<h6>
Also note that <code>x.Tags</code> is an optional parameter for <strong>each</strong>
available overload. Just add it as a last parameter to
<code>@Html.CheckBoxListFor( ... , x => x.Tags)</code>
checkbox list call
</h6>
</section>
<h4 class="col_12 center">For more information and discussion see</h4>
<div class="col_12 center">
<a href="@ViewBag.CodePrejectUrl" class="button large pop">
<span class="icon" data-icon="?"></span>
Extension's Article on CodeProject.com
</a>
</div>
</div>