CheckBoxList.Mvc.Core 1.0.0

dotnet add package CheckBoxList.Mvc.Core --version 1.0.0
                    
NuGet\Install-Package CheckBoxList.Mvc.Core -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CheckBoxList.Mvc.Core" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CheckBoxList.Mvc.Core" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CheckBoxList.Mvc.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CheckBoxList.Mvc.Core --version 1.0.0
                    
#r "nuget: CheckBoxList.Mvc.Core, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CheckBoxList.Mvc.Core@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CheckBoxList.Mvc.Core&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CheckBoxList.Mvc.Core&version=1.0.0
                    
Install as a Cake Tool

CheckBoxList.Mvc.Core

NET 5.x (.NET Core) port of Stephen Zeng's CheckBoxList.Mvc for .NET Framework 4.x (https://github.com/stephenzeng/CheckBoxList.Mvc)

CheckBoxList.Mvc.Core

#####Extension methods for CheckBoxList in MVC

Overview

CheckBoxList.Mvc.Core aims to help you to code for mulitple selctions in ASP.NET MVC in the, well, MVC way. For example in the view @Html.TextBoxFor(m => m.Name) gives you a textbox input and other out-of-box benefits from ASP.NET MVC. With CheckBoxList.Mvc.Core you now can do the similar thing with the following methods:

  • @Html.CheckBoxList("name", list)
  • @Html.CheckBoxListFor(m => m.List)

list and m.List are type of IList<CheckBoxListItem>

  • @Html.EnumCheckBoxList("name", list)
  • @Html.EnumCheckBoxListFor(m => m.List)

list and m.Listare type of IList<TEnum>

Nuget package

You can search CheckBoxList.Mvc.Core in Nuget Package Manager, or run the following command in the Package Manager Console to install it.

PM> Install-Package CheckBoxList.Mvc.Core

How to use it

The demo project contains 4 simple examples of using the 4 extension methods which should be able to help you to start with.

Support for Enum list

It can be quite handy to use a list of enum types in your models for multiple choices, since the type itself already has all the available options, so that what contained in the model list is what options selected. EnumCheckBoxList() and EnumCheckBoxListFor() are for this purpose.

######Enum

public enum ExtremeSport
{
    [Description("Bungee jumping")]
    BungeeJumping = 0,

    [Description("Deep diving")]
    DeepDiving = 1,

    Kitesurfing = 2,

    Parachute = 3,
}

######ViewModel

public class ExtremeSportViewModel
{
    public ExtremeSportViewModel()
    {
        ExtremeSports = Enumerable.Empty<ExtremeSport>().ToList();
    }

    [Display(Name = "Do you do any of the extreme sports listed below in your spare time?")]
    public IList<ExtremeSport> ExtremeSports { get; set; } 
}

######Controller actions

public ActionResult ExampleEnumCheckBoxListFor()
{
    var viewModel = new ExtremeSportViewModel();
    viewModel.ExtremeSports.Add(ExtremeSport.RockClimbing);

    return View(viewModel);
}

[HttpPost]
public ActionResult ExampleEnumCheckBoxListFor(ExtremeSportViewModel viewModel)
{
    if (ModelState.IsValid)
    {
        var selectedOptions = viewModel.ExtremeSports.Select(e => e.GetEnumDisplayName());
        ViewBag.SelectedOptionsText = string.Join(", ", selectedOptions);
    }

    return View(viewModel);
}

######View

@using (Html.BeginForm())
{
    <div class="form-group">
        @Html.LabelFor(m => m.ExtremeSports)
        @Html.EnumCheckBoxListFor(m => m.ExtremeSports)
    </div>
    <div>
        <button type="submit" class="btn btn-default">Submit</button>
    </div>
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 12,514 3/3/2021

Initial release