0

Can Angular syntax be included in Razor:

In the code below I am trying to say if "p.name" is not equal to "Select All" display an image but I dont think I can include {{p.name}} in the if statement

<div ng-repeat="p in Data.platforms">
    <div style="font-size: smaller">
        <input type="checkbox" ng-model="p.selected" />

        @if ("p.name" != "Select All") {
            <img ng-src="{{'/Content/img/'+p.name+'.jpg'}}" width="16" height="16" alt="{{p.name}}" />
        } 

        {{p.name}}
    </div>
</div>
4

2 回答 2

2

in Razor you are comparing two strings that will never be equal. "p.name" != "Select All" will always be true.

This all takes place before angular.

In angular you can use ng-show

<div ng-repeat="p in Data.platforms">
    <div style="font-size: smaller">
        <input type="checkbox" ng-model="p.selected" />
        <img ng-show="p.name != 'Select All'" ng-src="{{'/Content/img/'+p.name+'.jpg'}}" width="16" height="16" alt="{{p.name}}" />
        {{p.name}}
    </div>
</div>
于 2013-09-12T15:51:53.610 回答
0

You can't do that since Razor has no idea about what the value of p.name evaluates.

However you can achieve it with AngularJS

<img ng-show="p.name!= 'Select All'" ng-src="{{'/Content/img/'+p.name+'.jpg'}}" width="16" height="16" alt="{{p.name}}" />
于 2013-09-12T15:53:21.583 回答