-1

我有这个下拉列表,如下所示,我想根据可用数据预先选择一个项目。但它不起作用。始终选择最后一个选项。

<select id = @ids>
    <option value="0" @item.SchoolType == " " ? selected ></option>
    <option value="1" @item.SchoolType == "Primary School" ? selected>Primary School</option>
    <option value="2" @item.SchoolType == "Middle School" ? selected>Middle School</option>
    <option value="3" @item.SchoolType == "High School" ? selected>High School</option>
    <option value="4" @item.SchoolType == "University" ? selected>University</option>
</select>

如何解决这个问题。

谢谢

RJ

4

1 回答 1

0

试试这个,将您的代码更改为

@(item.SchoolType == "Middle School" ? "selected" : string.Empty)

您没有正确使用三元运算符

于 2013-06-11T08:01:42.980 回答