Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eliotjones/mvcradiobuttons
https://github.com/eliotjones/mvcradiobuttons
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/eliotjones/mvcradiobuttons
- Owner: EliotJones
- License: mit
- Created: 2015-02-10T18:43:39.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-04-23T18:22:32.000Z (over 9 years ago)
- Last Synced: 2024-10-02T12:15:44.374Z (about 1 month ago)
- Language: C#
- Size: 1.01 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
# MVC Radio Buttons
## Installation ##
The NuGet package can be installed using the NuGet GUI or Package Manager Console:
```Install-Package EliotJones.RadioButtons```
To uninstall simply remove the NuGet or use the Package Manager Console:
```Uninstall-Package EliotJones.RadioButtons```
## Usage ##
You need a ViewModel/Model with a property with one of the following types:
+ ```StringGuidRadioButtons```
+ ```StringIntRadioButtons```
+ ```StringStringRadioButtons```
+ ```StringRadioButtons```The naming follows the ```[Key][Value]RadioButtons``` pattern where Key is the type of the data used to label the button and value is the value of the button when selected.
For instance if you have a status table you want to bind to radio buttons with the structure:
1. New
2. Open
3. ClosedYou would use a StringIntRadioButtons property.
The ViewModel below has the Peppers property which uses this type:
public class PepperStuff
{
public StringIntRadioButtons Peppers { get; set; }
public int Quantity { get; set; }
}You can then map your collection to the property, you only need to provide the possible values as shown below:
PepperStuff capsicums = new PepperStuff
{
Quantity = 0,
Peppers = new StringIntRadioButtons
{
PossibleValues = new List>
{
new RadioButtonPair
{
Key = "red",
Value = 0
},
new RadioButtonPair
{
Key = "yellow",
Value = 1
},
new RadioButtonPair
{
Key = "green",
Value = 2
}
}
}
};There is an overloaded constructor allowing you to map a ```IEnumerable>``` to the PossibleValues field.
You can also provide the SelectedValue if the radio buttons are on an edit view.
Once you have your ViewModel you can get the radio button view by simply putting this in your View:
@Html.EditorFor(m => m.Peppers)
## Edit The View Layout ##
This NuGet package gives you complete control over the generated HTML for your radio button list. The views are stored in Views > Shared > EditorTemplates. You can edit the HTML though be careful what you change as it may break everything!
## Roll your Own ##
Classes should inherit from ```RadioButtonCollection```. Once you have a named class, **create an EditorTemplate with a
corresponding name**. You should be able to copy the existing EditorTemplates and rename the view and change the model to the correct type.