Reputation: 408
I want to send the checked radio button value to server in angular
i tried but i am getting 500 server error
where as when i am sending only question id that is working
here is the code for CreateController
var CreateController = ['$scope', '$http', function ($scope, $http) {
$scope.mydata = 'ajs works';
$scope.model = {
Questions:{}
};
$http.get('/Testing/IndexVM').success(function (newdata) {
$scope.model = newdata;
});
$scope.NextQuestion = function () {
$http.post('/Testing/NextQuestion', {
quid: $scope.model.Questions.AddQuestionID, selectedopt: $scope.model.Questions.Options.OptionID
}).success(function (newdata) {
$scope.model = newdata;
});
}];
and here is the code for index view what i am tring to send
<div ng-controller="CreateController">
<tr>
<td>
<h3>Question: {{model.Questions.Question}}</h3>
</td>
</tr>
<tr ng-repeat="item in model.Questions.Options" ng-model="model.Questions.Options.OptionID">
<td class="switch radius">
<input id="{{item.Options}}" type="radio" name="selectedvalue" value="{{item.Options}}">
<label for="{{item.Options}}"></label>{{item.Options}}
</td>
</tr>
</div>
Upvotes: 1
Views: 846
Reputation: 1238
move the ng-model to the input element so that every radio button has the same ng-model and same name attribute than u have a radio button group and the model has the value of the selected value attribute
so ng-model="model.Questions.Options.OptionID" not "item"
Upvotes: 1
Reputation: 690
Add ng-model in your radio buttons:
<input id="{{item.Options}}" type="radio" name="selectedvalue" value="{{item.Options}} ng-model="item">
Upvotes: 0