5

I use Asp.Core 2.1 with "Page Razor Crud" and I want into my page show a dropdownlist.

Here's my model:

public enum EnumStatus
    {
        Waiting,
        [Display(Name = "Development progress")]
        Progress,
        Canceled,
        Refused,
        Deployed,
    }
    public class Improvement
    {
        [Key]
        public int ID { get; set; }

        public string Title { get; set; }

        [DataType(DataType.Text)]
        public string Description { get; set; }

        public EnumStatus Status { get; set; }
    }

the CRUD Razor Page generated this line:

<select asp-for="Improvement.Status" class="form-control"></select>

But it's empty. After researchs, i found I need to add asp-items. But at this point, all solutions I tested failed.

Best regards,

1 Answer 1

14

Try the following code in the view:

<select asp-for="Status" 
        asp-items="Html.GetEnumSelectList<EnumStatus>()" 
        class="form-control>
    <option selected="selected" value="">Please select</option>
</select>

Here Status is the property of your Improvement model class while EnumStatus is the name of your enum type.

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

2 Comments

Thanks for your answer, "<EnumStatus*> missing assembly?
add fully qualified name with namespace or add using statement

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.