How to create a dynamic checkboxlist group in C# MVC?
<p>How do I create a dynamic checkboxlist groups in C# MVC Razor View as shown in the picture below.</p>

<p>Let say the group category is CO2 and there are sub-items below it which example shown test and test2.</p>

<p>looks ok with my current code but how do i do the sub-items in it?</p>

<p><a href="https://i.stack.imgur.com/UF7Uo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UF7Uo.png" alt="enter image description here"></a></p>

<p>This is my Current Code for Model</p>

<pre><code>public class Sites
{
    public int SiteId { get; set; }

    public string SiteName { get; set; }

    public bool IsCheck { get; set; }
}

public class SiteList
{
    public List&lt;Sites&gt; sites { get; set; }
}
</code></pre>

<p>Controller</p>

<pre><code>public ActionResult sitechecklist()
    {
        List&lt;Sites&gt; site = new List&lt;Sites&gt;();
        site.Add(new Sites() { SiteId = 1, SiteName = "CO2", IsCheck = false });
        site.Add(new Sites() { SiteId = 2, SiteName = "CO3", IsCheck = false });
        site.Add(new Sites() { SiteId = 3, SiteName = "IO", IsCheck = false });
        site.Add(new Sites() { SiteId = 4, SiteName = "NCC01", IsCheck = false });
        SiteList sList = new SiteList();
        sList.sites = site;
        return View(sList);
    }
</code></pre>

<p>my View</p>

<pre><code>&lt;ul&gt;
            @for (int i = 0; i &lt; Model.sites.Count; i++)
            {
                &lt;li&gt;
                    @Html.CheckBoxFor(m=&gt;Model.sites[i].IsCheck)
                    @Model.sites[i].SiteName
                    @Html.HiddenFor(m=&gt;Model.sites[i].SiteId)
                    @Html.HiddenFor(m=&gt;Model.sites[i].SiteName)
                &lt;/li&gt;
            }
        &lt;/ul&gt;
</code></pre>