2016-03-25 25 views
1

kullanarak MVC kumandanın Mesaj yöntemi hatası alıyorum ama benim kod hep asp.net denetleyicisi sonrası talep üzerine kırar ve buBen angualarJS ve asp.net web API kullanıyorum angularjs

var hatadır

EntityFramework.dll dosyasında 'System.ArgumentNullException' türünde bir istisna oluştu ancak kullanıcı kodu Ek bilgisinde ele alınmadı: Değer boş bırakılamaz.

bu angularjs kontrolörünü gelişmiş

+0

Denetleyici için bir JSON isteği ve giriş modeli gösterebilir misiniz? –

+0

bu JSON var obj = $ .param'dır ({ ad: $ kapsamı.Name } }); –

+1

"pcate" null değilse hata ayıklama modunda kontrol ettiniz mi? Ayrıca neyin yayınlandığını kontrol etmeye çalıştın mı? –

cevap

1

Burada yerel bir değişken obj yaratıyor

$http.post("/api/productCategory/", this.obj) 

Ya this.obj oluşturmak var obj yerine veya yerine postanıza obj geçirin .

+0

Tanrı sizi korusun, Genius !! çalışıyor! Güzel gözlem! –

0

yılında

var appcat = angular.module("PharmacyControllers", ['ngRoute']); 

appcat.controller("createController", ['$scope', '$http', '$location', function ($scope, $http, $location) 
{ 
    $scope.submit = function() 
    { 
     //converting the object to JSON 
     var obj = { 

      Name: $scope.Name 
     }; 
     //alert(obj); 
     $http.post("/api/productCategory/", this.obj).success(function (data) { 
      $location.path('/list'); 
     }).error(function (data) { 

      $scope.error = "An error has occured while adding product Category! " + data.ExceptionMessage; 
     }); 
    } 

}]); 

sayesinde MVC yöntemi

// POST: api/ProductCategory 
    public HttpResponseMessage Post(ProductCategory pcate) 
    { 
     if (ModelState.IsValid) 
     { 

      this.pcat.pcategory.Add(pcate); 
      this.pcat.SaveChanges(); 
      return Request.CreateResponse(HttpStatusCode.Created, pcate); 
     } 
     else 
     { 
      return Request.CreateResponse(HttpStatusCode.BadRequest, pcate); 
     } 
    } 

olduğu gelen değiştirmeyi deneyin:

$http.post("/api/productCategory/", this.obj).success(function (data) { 
.210

için:

var obj = { 
    Name: $scope.Name 
}; 

Ama sonra API this.obj sonrası çalışıyorsanız:

$http.post("/api/productCategory/", { pcate: obj }).success(function (data) { 
+0

Bu çalışmıyor! Ayrıca, var obj = $ .param ({ pcate: { Adı: $ kapsamı.Name } }); ama yine de aynı hata –

+0

@LLJanneh Ürün Sınıfı neye benziyor? – DaveB

İlgili konular