1

I am calling a question from server using http.post

where i want to pass selected optionid from the data i got from http.get

please tell me what to do

here is the code of CreateController.js

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}).success(function (newdata) {

            $scope.model.Questions.push(newdata);

        });


    };
    //delete $http.defaults.headers.common['X-Requested-With'];


}];

here is the view

<h2></h2>

<div ng-controller="CreateController">
    <table class="ui-sortable-handle">
        <tr>
            <td>
                <input type="hidden" id="qid" ng-model="model.Questions.AddQuestionID" />
            </td>
        </tr>
        <tr>
            <td>
                <input type="hidden" id="complevel" ng-model="model.Questions.ComplexityLevel" />
                <input type="hidden" id="servcomplvl" ng-model="model.servercomplevel" />
            </td>
        </tr>
        <tr>
            <td>
                <h3>Question: {{model.Questions.Question}}</h3>
            </td>
        </tr>
        <tr ng-repeat="item in model.Questions.Options">
            <td class="switch radius">
                <input id="{{item.Options}}" type="radio" name="selectedvalue" value="{{item.Options}}">
                <label for="{{item.Options}}"></label>{{item.Options}}
            </td>
        </tr>

    </table>
    {{mydata}}


    <div class="nav-bar right">
        <ul class="button radius" id="myButton"  ng-click="NextQuestion()">Next</ul>
    </div>


    <div>

    </div>

    <div></div>
</div>
Khan Engineer
  • 408
  • 5
  • 23
  • Do you get any error messages? What happens? – Zaphod Jan 07 '15 at 08:46
  • no it brings question but i also want to send optionid i don't know how to send option id as well to server – Khan Engineer Jan 07 '15 at 08:51
  • i passed ng-model="item.Options.OptionID" then i got error Cannot read property 'OptionID' of null – Khan Engineer Jan 07 '15 at 08:54
  • where as i have five radio buttons i want to send the id of that one which is selected – Khan Engineer Jan 07 '15 at 08:55
  • Is your OptionId null, or is angular unable to get it? – Zaphod Jan 07 '15 at 08:58
  • What does the class Question and Option look like? – Zaphod Jan 07 '15 at 08:59
  • what do u mean i did not get you – Khan Engineer Jan 07 '15 at 09:07
  • now wit does nt get the AddquestionID as well it provides 500 server error – Khan Engineer Jan 07 '15 at 09:09
  • now the server error is ok – Khan Engineer Jan 07 '15 at 09:09
  • please tell me how to get the selected option radio from index view – Khan Engineer Jan 07 '15 at 09:10
  • when i write this code i get 500 error $http.post('/Testing/NextQuestion', { quid: $scope.model.Questions.AddQuestionID, selectedoption: $scope.model.Questions.Options.OptionID }) and when i remove the second parameter then it works – Khan Engineer Jan 07 '15 at 09:18
  • possible duplicate of [How can I get the value of the checked radio button when submitting a form using angularjs?](http://stackoverflow.com/questions/15166270/how-can-i-get-the-value-of-the-checked-radio-button-when-submitting-a-form-using) <-- this should help you, as what you're really asking is how to get radiobutton values. – Zaphod Jan 07 '15 at 09:28
  • but he is not passing the radio value in http post my problem is there – Khan Engineer Jan 07 '15 at 09:44
  • He describes how to get the value of the radio button, which is what you need. Your problem is that the $scope.model.Questions.Options.OptionID isn't giving you the right value. The response in the post shows how to get that value, and then you pass that value to your post method. – Zaphod Jan 07 '15 at 11:01

0 Answers0