[英]How do I create a drop down list using angular inside CSHTML?
如何在 CSHTML 中使用 angular 创建下拉选择列表? 我尝试了以下两个选项,但都不起作用。 选项1
<div class="col-sm-2">
<div class="form-group">
<label for="customers">Customer</label>
<input id="{{customer.CustomerProfileId}}" ng-model="filter.customers" type="text" class="form-control selected" />
</div>
</div>
选项#2
<div class="col-sm-2">
<div class="form-group">
<label for="customers">Customer2</label>
<select id="{{customer.CustomerProfileId}}" ng-model="filter.customers" ng-options="for customer in filter.customers" type="text" class="form-control">{{customer.CustomerName}}</select>
</div>
</div>
修订版 #2:感谢您的帮助,这个版本肯定更接近了。 除了我没有在 customerChange 事件中捕获 CustomerProfileId 之外,大部分都有效。 如何识别所选的客户 ID?
<div class="col-sm-2">
<div class="form-group">
<label for="customers">Customer</label>
<select class="form-control" ng-model="parameters.AvaliableCustomers" ng-change="customerChange(c.CustomerProfileId)" ng-options="c.CustomerName for c in parameters.AvaliableCustomers track by c.CustomerProfileId">
<option value="">-- Select --</option>
</select>
</div>
</div>
JS代码:
$scope.customerChange = function (customerId) {
var temp = customerId;
}
选项1:
@Html.DropDownListFor(model => model.Gender, new List<SelectListItem>(), new { @class = "form-control", @ng_model = "gender", @ng_options = "item as item.name for item in genders track by item.value" })
选项 2:
<select name="Gender" ng-options="item as item.name for item in genders track by item.value" ng-model="gender"></select>
*.js
$scope.genders =
[
{ value: "M", name: "Male" },
{ value: "F", name: "Female" }
];
像这样尝试
<select formControlName="countryControl" [(ngModel)]="filter.customers">
<option [value]="customer.CustomerProfileId" *ngFor="let customer of filter.customers"> {{customer.CustomerName}}</option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.