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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

try this:

ng-options="stage.StageId as stage.StageName for stage in stages"

2 Comments

'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].
Seems to work, but without the 'stage identify' at the beginning

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.