Ankit  Shukla

Ankit Shukla

  • NA
  • 681
  • 110.9k

Problem in insert dropdown value in asp.mvc using angularjs

Aug 7 2017 1:19 AM
Hello,
 
       Insert.cshtmll -
 
<select ng-model="ClassSeatMaster.ClassName" data-ng-options="c as c.ClassName for c in allItems" class='form-control'>
<option value="">-- Select Class --</option>
</select>
 
Api controler to bind dropdown
 
public JsonResult GetClass()
{
using (TravelAgencyEntities context = new TravelAgencyEntities())
{
var ClassList = context.ClassMasters.Select(x => new { x.ClassName, x.ID }).ToList();
return Json(ClassList, JsonRequestBehavior.AllowGet);
}
}
 
AngularJS Dropdown binding Code 
 
function GetAllClass() {
$http({
method: 'Get',
url: '/ClassDDL/GetClass'
}).success(function (data, status, headers, config) {
$scope.allItems = data;
}).error(function (data, status, headers, config) {
$scope.message = 'Unexpected Error';
});
}
 
AngularJS insert Code
 
$scope.save = function () {
alert($scope.ClassSeatMaster.SeatType);
if ($scope.ClassSeatMaster.SeatType != '' && $scope.ClassSeatMaster.ClassName != '')
{
$http({
method: 'POST',
url: 'api/SeatTypeAPI/AddSeatType',
data: $scope.ClassSeatMaster
}).then(function successCallback(response) {
$scope.SeatTypeData.push(response.data);
alert('Inserted successfully!!');
$scope.addnewdiv = false;
}, function errorCallback(response) {
alert('error:' + response.data.ExceptionMesage);
});
}
else {
alert('Please enter all Mandatory Fields!!');
}
};
 
When I am inserting record data inserts successfully. but blank data inserts. When I tried to get selected dropdown value using "alert($scope.ClassSeatMaster.SeatType);" it shows message "Object object" in place of selected value.
 
Please help to insert dropdown selected value. 

Answers (2)