Add constructor for the SelectListItem class

This commit is contained in:
Fabien Lavocat 2018-01-24 07:43:13 -08:00
parent 381ac2946c
commit 88e14a0bfe
2 changed files with 13 additions and 18 deletions

View File

@ -64,24 +64,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{
return new List<SelectListItem>
{
new SelectListItem
{
Text = Resources.Common_TriState_NotSet,
Value = string.Empty,
Selected = !value.HasValue
},
new SelectListItem
{
Text = Resources.Common_TriState_True,
Value = "true",
Selected = (value == true),
},
new SelectListItem
{
Text = Resources.Common_TriState_False,
Value = "false",
Selected = (value == false),
},
new SelectListItem(Resources.Common_TriState_NotSet, string.Empty, !value.HasValue),
new SelectListItem(Resources.Common_TriState_True, "true", (value == true)),
new SelectListItem(Resources.Common_TriState_False, "false", (value == false)),
};
}

View File

@ -10,6 +10,16 @@ namespace Microsoft.AspNetCore.Mvc.Rendering
/// </summary>
public class SelectListItem
{
public SelectListItem() { }
public SelectListItem(string text, string value, bool selected = false, bool disabled = false)
{
Disabled = disabled;
Selected = selected;
Text = text;
Value = value;
}
/// <summary>
/// Gets or sets a value that indicates whether this <see cref="SelectListItem"/> is disabled.
/// This property is typically rendered as a <code>disabled="disabled"</code> attribute in the HTML