asp.core页面razor枚举下拉列表 [英] asp.core page razor enum dropdownlist
本文介绍了asp.core页面razor枚举下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将Asp.Core 2.1与"Page Razor Crud"一起使用,并且希望在我的页面中显示一个下拉列表.
I use Asp.Core 2.1 with "Page Razor Crud" and I want into my page show a dropdownlist.
这是我的模特:
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; }
}
CRUD剃刀页面生成以下行:
the CRUD Razor Page generated this line:
<select asp-for="Improvement.Status" class="form-control"></select>
但是它是空的.经过研究,我发现我需要添加asp项目.但是在这一点上,我测试过的所有解决方案都失败了.
But it's empty. After researchs, i found I need to add asp-items. But at this point, all solutions I tested failed.
最诚挚的问候,
推荐答案
在视图中尝试以下代码:
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>
此处 Status
是您的 Impprovement
模型类的属性,而 EnumStatus
是您的枚举类型的名称.
Here Status
is the property of your Improvement
model class while EnumStatus
is the name of your enum type.
这篇关于asp.core页面razor枚举下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文