How to Make ChecklBox Readonly in Asp.Net Core 8 MVC (.cshtml)

How to make checkbox radonly in asp.net core 8 mvc application with disabled attribute. Make checkbox not to select in asp.net mvc. C#.net
In this article I will show you how you can make a checkbox readonly in your asp.net core 8 mvc application. Here first we will create a new asp.net core 8 mvc application and add a controller. After adding controller, we will create the view. After creating view will add the below code. 

@{
    ViewData["Title"] = "Home Page";
}
<h2>Read Only Checkbox</h2>
<br />
@Html.CheckBox("chkTerm", false, new { @class = "form-check-input", @disabled = "disabled" })
    Disable check box with checked false
<br />
@Html.CheckBox("chkTerm", true, new { @class = "form-check-input", @disabled = "disabled"})
    Disable check box with checked true
In above code I have taken two checkboxes control on with check and one with un-checked property. To make the checkbox checked we will pass the value as true and to make the checkbox un-checked we will pass false.

Now we will make the checkbox readonly we will use the property disabled="disabled". This will make the checkbox read only and user will not be able to click on it. Now we will the run the code to check the output. 
Make ChecklBox Readonly in Asp.Net core MVC 8 (html,.cshtml)

Now to make the check box enable we only need to remove disabled="disabled". Here is the code with no disabled="disabled" tag. 
@Html.CheckBox("chkTerm", false, new { @class = "form-check-input"})
    Disable check box with checked false
<br />
@Html.CheckBox("chkTerm", true, new { @class = "form-check-input" })
    Disable check box with checked true
Now run the code to check the output. 

make checkbox enabled in asp.net core mvc

Post a Comment