3

Let's say I have an enumeration like this:

public enum ContactPhoneType
{
    [Display(Name = "")]
    None = 0,

    [Display(Name = "Home Phone")]
    HomePhone = 1,

    [Display(Name = "Cell/Mobile Phone")]
    CellMobile = 2,

    [Display(Name = "Work Phone")]
    Work = 3,

    [Display(Name = "Family Member")]
    FamilyMember = 4,

    [Display(Name = "Fax Number")]
    Fax = 5,

    [Display(Name = "Other")]
    Other = 6,
}

I want to display only the first 6 from the list. How can I hide the last one?

For showing all the items, I have used the below code:

<div class="form-group">
   <label class="col-sm-4 control-label" asp-for="PhoneNumberType"></label>
      <div class="col-sm-6">
        <select asp-for="PhoneNumberType" asp-items="Html.GetEnumSelectList<ContactPhoneType>()" class="form-control"></select>
       </div>
</div>

1 Answer 1

5

If the method returns a collection that inherits from IEnumerable<T>, you can use Take() method to select first N number of elements of it following way :

asp-items="Html.GetEnumSelectList<ContactPhoneType>().Take(6)"

Hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.