问题
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:
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.
来源:https://stackoverflow.com/questions/53741589/asp-core-page-razor-enum-dropdownlist