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>
1
  • no you can't use values in javascript variables for razor (which renders server-side). Commented Sep 12, 2013 at 15:53

2 Answers 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>
Sign up to request clarification or add additional context in comments.

Comments

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}}" />

1 Comment

Doesn't work, it will always show the image. See stackoverflow.com/a/18768940/1873485 for more details as to why.

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.