我正在创建一个页面来编辑不合格报告。该页面采用如下模型:
在页面上,我试图显示一个下拉列表,其中FaultCode
预先选择了属性的当前值。但是,它不起作用。相反,我将其剥离回基础并尝试对预选值进行硬编码,如下所示:
@{
var faultCodeList = new List<SelectListItem>
{
new SelectListItem { Text = "Internal Damage", Value = "Internal Damage" },
new SelectListItem { Text = "Customer Problem", Value = "Customer Problem" },
new SelectListItem { Text = "Incorrect Material Supplied", Value = "Incorrect Material Supplied" },
new SelectListItem { Text = "Received Material Damaged", Value = "Received Material Damaged" },
new SelectListItem { Text = "No Test Certificate Supplied", Value = "No Test Certificate Supplied" },
new SelectListItem { Text = "Other", Value = "Other", Selected = true}
};
}
@Html.DropDownList("FaultCode", faultCodeList)
这仍然不起作用。但是,如果我将该字段的名称更改为其他名称FaultCode
- 即FaultCode2
- 它可以正常工作!
为什么我会看到这种奇怪的行为?在同一页面上,我有其他字段的下拉列表,它们运行良好......