1

Consider the following Razor view - Let's call it VIEW-1 :

<h2>Index</h2>

@if (true)
{
    <img src="/Content/images/black_square.png" alt="Black Square" />
}

<img src="/Content/images/black_square.png" alt="Black Square" />

When I load the VIEW-1 into Internet Explorer 8 or Mozilla Firefox 9.0.1 the two "black square" images are separated by a space.
But I do not want the two images separated.

Now consider the following Razor view - Let's call it VIEW-2 :

<h2>Index</h2>

<img src="/Content/images/black_square.png" alt="Black Square" /><img src="/Content/images/black_square.png" alt="Black Square" />

When I load the VIEW-1 in Internet Explorer 8 or Mozilla Firefox 9.0.1 the two "black square" images are not separated by a space.

VIEW-1 and VIEW-2 are example views.
The "separated images" fact is a little problem in one of my ASP .NET MVC 3 project.
I can not write all my image elements on one line because some of them depend on condition statements and loop statements.

Is there a way to get image elements not separated by a space even if they are not written on the same line ?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
user1139666
  • 1,687
  • 4
  • 24
  • 45
  • you can use an helper method for generate img elements – Yorgo Feb 17 '12 at 08:31
  • Here's the same question on Stackoverflow, with an accepted answer: http://stackoverflow.com/questions/2628050/ignore-whitespace-in-html – Pbirkoff Feb 17 '12 at 08:34

3 Answers3

1

Surprisingly, Razor lets you do this:

<h2>Index</h2>

@if (true)
{
    <img src="/Content/images/black_square.png" alt="Black Square" />}<img src="/Content/images/black_square.png" alt="Black Square" />

... though whenever I do, I add an apologetic comment nearby explaining why I've done it.

teedyay
  • 23,293
  • 19
  • 66
  • 73
1

You could try using CSS:

<div class="pictures">
    @if (true)
    {
        <img src="/Content/images/black_square.png" alt="Black Square" />
    }
    <img src="/Content/images/black_square.png" alt="Black Square" />
</div>

and then:

.pictures img {
    float: left;
}

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
-1

You can solve this by inserting the images into a 1 row and 1 cell table:

<table>
@if (true)
{
    <img src="/Content/images/black_square.png" alt="Black Square" />
}

<img src="/Content/images/black_square.png" alt="Black Square" />
</table>
Guy Dubrovski
  • 1,542
  • 1
  • 20
  • 25