This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making the HtmlHelper.GetEnumSelectList take DisplayAttribute.GroupNa…
…me into account to create select groups.
- Loading branch information
Showing
13 changed files
with
191 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace MvcSample.Web.Models | ||
{ | ||
public enum TestEnum | ||
{ | ||
Zero = 0, | ||
[Display(GroupName = "Primes")] | ||
One = 1, | ||
[Display(GroupName = "Evens", Name = "Dos")] | ||
Two = 2, | ||
[Display(GroupName = "Primes")] | ||
Three = 3, | ||
[Display(Name = "4th")] | ||
Four = 4 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/EnumGroupAndName.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.AspNet.Mvc.ModelBinding | ||
{ | ||
/// <summary> | ||
/// An abstraction used when grouping enum values for <see cref="ModelMetadata.EnumGroupedDisplayNamesAndValues"/>. | ||
/// </summary> | ||
public struct EnumGroupAndName | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the EnumGroupAndName structure. | ||
/// </summary> | ||
/// <param name="group">The group name.</param> | ||
/// <param name="name">The name.</param> | ||
public EnumGroupAndName(string group, string name) | ||
{ | ||
if (group == null) | ||
{ | ||
throw new ArgumentNullException(nameof(group)); | ||
} | ||
|
||
if (name == null) | ||
{ | ||
throw new ArgumentNullException(nameof(name)); | ||
} | ||
|
||
Group = group; | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the Group name. | ||
/// </summary> | ||
public string Group { get; } | ||
|
||
/// <summary> | ||
/// Gets the name. | ||
/// </summary> | ||
public string Name { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.