0

I am trying to post my Angular form to my Post method in my Api Controller :

    <div data-ng-app="app" ng-controller="FixtureAddController">
    <form name="form" class="col-xs-2" id="form" class="form-horizontal">
        <div class="control-group" ng-class="{error: form.StageName.$invalid}">
            <label class="control-label" for="StageName">Stage Team</label>
            <div class="controls">
                <select class="form-control" ng-model="fixture.StageName" ng-options="stage.StageName as stage.StageName for stage in stages" required>
                    <option style="display:none" value="">Select</option>
                </select>
                <span ng-show="form.StageName.$dirty && form.StageName.$error.required">Stage required</span>
            </div>
        </div>

....other fields....

        <div class="form-actions">
            <button ng-show="form.$valid" ng-click="save()" class="btn btn-primary">{{action}}</button>
            <a href="/Admin/Fixtures/List" class="btn btn-danger">Cancel</a>
        </div>
    </form>
</div>

Whether I set ng-model to fixture.StageName or fixture.StageId, it always passes the StageName to my Post method, but I need it to pass the StageId. How do I get the Id to be passed?

user517406
  • 13,623
  • 29
  • 80
  • 120

2 Answers2

1

Try changing ng-options as well to use StageId. See also: Working with select using AngularJS's ng-options

Community
  • 1
  • 1
Alexander Vasilyev
  • 1,273
  • 2
  • 15
  • 22
0

try this:

ng-options="stage.StageId as stage.StageName for stage in stages"
Eugene P.
  • 2,645
  • 19
  • 23
  • 'Identity gives me a syntax error : Error: [$parse:syntax] Syntax Error: Token 'identify' is an unexpected token at column 7 of the expression [stage identify by stage.StageId] starting at [identify by stage.StageId]. – user517406 Feb 02 '14 at 13:17
  • Seems to work, but without the 'stage identify' at the beginning – user517406 Feb 02 '14 at 13:24