0

I current have a foreach statement, which shows a group of images using a URL stored within the database.

Some of the records, however, haven't been assigned a picture yet, so I want any records with a missing URL to show a generic image.

Here's the code I currently have:

@foreach(var row in qPropertyDetails) {
    <div class="container">
        <div class="row">
            <div class="span12" style="padding-bottom: 10px">
                <div class="row thumb-pad">
                    <div class="span4">
                        <img src="@row.PrimaryImage" alt="">
                    </div>
                </div>
            </div>
        </div>
    </div>
}

I'm guessing I need an IF statement within the foreach loop, but I don't know the correct syntax. I'm guessing maybe it's something like:

@foreach(var row in qPropertyDetails) {
    <div class="container">
        <div class="row">
            <div class="span12" style="padding-bottom: 10px">
                <div class="row thumb-pad">
                    @if (@row.PrimaryImage=Null) {
                        <div class="span4"><img src="~\tempimage.jpg" alt=""></div>
                    }
                    else {
                         <div class="span4"><img src="@row.PrimaryImage" alt=""></div>    
                    }
                </div>
            </div>
        </div>
    </div>
}

But that doesn't work.

4

1 回答 1

1

检查 null 的正确语法是:@if (@row.PrimaryImage == null) {

于 2013-04-10T15:37:16.647 回答