私は角度jsからアクションメソッドにデータを渡しているときに、アクションメソッドでnull値を取得しています。私はデバッグし)サーバは500(内部サーバーエラーのステータスで応答した(それはAddCutomer方法にヒットが、データがnull参照のこと。誰もがこの問題サーバーが500のステータス(内部サーバーエラー)(asp.net mvcと角度js)で応答しました
Admin.jsに修正するために私を助けることができる
var app = angular.module("adminmdl", [])
app.controller("admincontroller", function ($scope, AdminService) {
$scope.Action = 'Add';
GetAllCustomer();
function GetAllCustomer() {
var getcust = AdminService.getCustomer();
getcust.then(function (cust) {
$scope.customers = cust.data;
}, function() {
alert('Error');
});
}
$scope.data = {
cus_code: '',
cus_name: ''
}
$scope.savecu = function() {
AdminService.saveCustomerDdetails($scope.cusmodel).then(function (d) {
$scope.msg = "Insert Successfully";
});
}
})
.service('AdminService', function ($http) {
this.getCustomer = function() {
return $http.get('GetCustomer');
}
this.saveCustomerDdetails = function (customer) {
return $http.post('/AddCutomer', customer);
}
})
ASP.NET MVC
[HttpPost]
public JsonResult AddCutomer(Customer customer) {
te.Customers.Add(customer);
te.SaveChanges();
string message = "Success";
return new JsonResult { Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
htmlコード
<form class="form-horizontal" method="post" ng-submit="savecu()" name="basic_validate" id="basic_validate" novalidate="novalidate">
<div class="control-group">
<label class="control-label">Customer Code</label>
<div class="controls">
<input type="text" ng-model="cusmodel.Customercode" name="required" id="required" >
</div>
</div>
<div class="control-group">
<label class="control-label">Customer Name</label>
<div class="controls">
<input type="text" ng-model="cusmodel.Customername" name="name" id="name" >
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" value="Save" ng-click="savecu()" class="btn btn-success">
<input type="submit" value="Clear" 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>
でそれを使用 { [System.Diagnostics.CodeAnalysis.SuppressMessage(」customer.cs定義 –
公共部分クラスの顧客を共有してください。公開の顧客() { this.projects = new HashSet();このユーザーは、Microsoft Corporationの米国およびその他の国における登録商標または商標です。 } 公開ストリングcus_code {get;セット; } 公開ストリングcus_name {get;セット; } [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Usage"、 "CA2227:CollectionPropertiesShouldBeReadOnly")] public仮想ICollection projects {get;セット; } } –
@MarcusH私はcustomer.csを自動的に共有しています –