TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ankit Shukla
NA
681
117.6k
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.
Reply
Answers (
2
)
angular validation
Get data from json array