Check box in razor view in ASP.NET MVC

How to create a checkbox in the ASP.NET MVC view?

To create a CheckBox, we can use @Html.CheckBox html helper method. 
@Html.CheckBox("Active1")
Above code snippet creates a checkbox whose name attribute would be "Active1"
Ouptut
<input type="checkbox" name="Active1" />
If the View is using Model and the property is of type Bit (Boolean), we can use @Html.CheckBoxFor 
 @Html.CheckBoxFor(model => model.Active) 
Ouptut
<input type="checkbox" name="Active" />

No comments:

Post a Comment

How to register multiple implementations of the same interface in Asp.Net Core?

 Problem: I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { ...