How do you force a checkbox to be checked when created in a .cshtml file

Viewed 16

I'm creating multiple check boxes but I would like one to be automatically checked and unable to be unchecked by a user. Below is the base code for my check boxes.

<div class="form-control">
                    <div class="row"><span>1: @Html.CheckBoxFor(m => m.1, new {form = "mainForm"})</span></div>
                    <div class="row"><span>2: @Html.CheckBoxFor(m => m.2, new {form = "mainForm"})</span></div>
                    <div class="row"><span>3: @Html.CheckBoxFor(m => m.3, new {form = "mainForm"})</span></div>
                    <div class="row"><span>4: @Html.CheckBoxFor(m => m.4, new {form = "mainForm"})</span></div>
</div>

I tried adjusting my code to pass along several attributes to the html element like so but it didn't work.

<div class="form-control">
                    <div class="row"><span>1: @Html.CheckBoxFor(m => m.1, new {form = "mainForm"})</span></div>
                    <div class="row"><span>2: @Html.CheckBoxFor(m => m.2, new {form = "mainForm", checked = "true", value = "true"})</span></div>
                    <div class="row"><span>3: @Html.CheckBoxFor(m => m.3, new {form = "mainForm"})</span></div>
                    <div class="row"><span>4: @Html.CheckBoxFor(m => m.4, new {form = "mainForm"})</span></div>
</div>

I would like to avoid using jQuery here if possible as I can't get my jQuery functions to load from my partial view files.

0 Answers
Related