我有如下所示的下拉列表,我想根据可用数据预先选择一个项目。但它不起作用。始终选择最后一个选项。
<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
答案 0 :(得分:0)
试试这个,将代码更改为
@(item.SchoolType == "Middle School" ? "selected" : string.Empty)
您没有正确使用三元运算符