Asp.net Angularjs在select中包含一个空选项

Asp.net Angularjs在select中包含一个空选项,asp.net,angularjs,Asp.net,Angularjs,我有一个dropdownlist,数据以这种方式在页面加载时动态绑定: <asp:DropDownList ID="ddlSet" DataTextField="Title" DataValueField="PKSetId" runat="server" AppendDataBoundItems="true" ng-model="SetId"></asp:DropDownList> 呈现的html是: <select id="cpContent_ddlSet

我有一个dropdownlist,数据以这种方式在页面加载时动态绑定:

<asp:DropDownList ID="ddlSet" DataTextField="Title" DataValueField="PKSetId" runat="server" 
AppendDataBoundItems="true" ng-model="SetId"></asp:DropDownList>

呈现的html是:

<select id="cpContent_ddlSet" ng-model="SetId">
<option value="? undefined:undefined ?"></option>
<option value="3">Test3</option>
</select>

测试3
加载页面时,默认情况下应选择Test3选项,但不会发生这种情况。我本应该设置
$scope.SetId=3
,但之前不知道这个值

我在这里看到了类似的问题,但DropDownList是以角度方式绑定数据的,您可以轻松地从$scope设置所选项目


如何解决这个问题。

你不能这样做

我建议首先添加选项,例如:

<option value="" disabled ng-selected> Make your choice:
做出选择:

要么构建服务器端ASP应用程序,要么构建客户端Angular应用程序,但不要混合使用这两种技术

让Angular完成整个前端逻辑和渲染,ASP只提供REST服务


有关如何预选下拉列表值的示例,请参见t。

将它们混合使用并不好。在selecteditem上快速搜索dropdownlist显示了在dropdownlist中设置(选择)项目的不同方式。我的建议是,在加载页面中设置所选项目。例如:{list}.SelectedValue=theValue.ToString()。