我正在尝试发布文本框的数据并选择List到AngularJS JavaScript函数。我使用ng-repeat加载数据以选择列表。数据正在加载但值未选择并传递给AngularJS函数。任何人都可以帮助解决这个问题
AngularJS代码
var app = angular.module('projectmdl', []);
app.controller('projectcontroller', function ($scope, projectservice) {
GetCustomer();
function GetCustomer() {
projectservice.GetCustomerDetails().then(function (d) {
$scope.customers = d.data;
}, function () {
alert("Error Loading Customer Details");
});
}
$scope.saveproject = function () {
var r = confirm("Are you sure you want to insert ?")
if (r == true) {
if ($scope.Action == 'Add') {
projectservice.AddProjectDetails($scope.project).then(function (d) {
LoadProjects();
var custcode = $scope.pr_custcode;
$scope.msg = 'Insert Successfully';
$scope.project = null;
$scope.pr_code = '';
$scope.pr_name = '';
$scope.pr_description = '';
}, function () {
LoadProjects();
});
}
}
else {
LoadProjects();
}
}
})
.service('projectservice', function ($http) {
this.GetCustomerDetails = function () {
var response = $http({
method: 'GET',
url: '/Admin/CustomerDetails',
datatype:'json'
});
return response;
}
});
HTML代码。
<form class="form-horizontal" method="post" name="basic_validate" id="basic_validate" novalidate="novalidate">
<div class="control-group">
<label class="control-label">Project Code</label>
<div class="controls">
<input type="text" ng-model="project.pr_code" name="required" id="required">
</div>
</div>
<div class="control-group">
<label class="control-label">Project Name</label>
<div class="controls">
<input type="text" ng-model="project.pr_name" name="name" id="name">
</div>
</div>
<div class="control-group">
<label class="control-label">Description</label>
<div class="controls">
<input type="text" ng-model="project.pr_description" name="name" id="name">
</div>
</div>
<div class="control-group">
<label class="control-label">Customer</label>
<div class="controls">
@*<select style="width:210px;" name="pr_custcode" id="pr_custcode" ng-model="project.pr_custcode">
<option ng-repeat="cu in customers" value="{{cu.cus_code}}" >{{cu.cus_name}}</option>
</select>
<tt>{{project.pr_custcode}}</tt>*@
<select name="singleSelect" ng-model="project.singleSelect">
<option ng-repeat="pr in customers" value="{{pr.cus_code}}">{{pr.cus_name}}</option>
</select><br>
<tt>singleSelect = {{project.singleSelect}}</tt>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" value="Save" ng-click="saveproject()" class="btn btn-success">
<input type="submit" value="Clear" ng-click="clearproject()" class="btn btn-success" />
</div>
</div>
<div class="control-group">
<div class="controls">
<p style="color:green">{{msg}}</p>
</div>
</div>
@*<div class="form-actions">
</div>*@</form>
ASP MVC代码
[HttpPost]
public string AddProjects(Project projects) {
if (projects != null)
{
te.Projects.Add(projects);
te.SaveChanges();
return "Project Add Successfully";
}
else {
return "Error";
}
}