Pranav
Pranav

Reputation: 447

Space in attribute value gets replaced by " (quotation mark)

When I insert a string with whitespace as an attribute value it gets replaced by a quotation mark. For example,

@foreach (string file in files) {
    <div class="item active">
       <img class="img-responsive" src=@file alt="Book cover">
    </div>
}

It gets rendered as

<div class="item active">
    <img class="img-responsive"     src="c:\users\raghav" sharma\documents\visual="" studio="" 2013\projects\bookhive\bookhive\content\images\0007282311-1.jpg="" alt="Book cover">
</div>

It's really pissing me off. I don't know why this happens I've searched the whole internet but got nothing so far.

Upvotes: 0

Views: 353

Answers (1)

Jason Evans
Jason Evans

Reputation: 29186

Use quotes around the value e.g.

src="@file"

That should wrap the value of @file like so:

src="c:\users\raghav sharma\documents\visual="

The Razor parser will be intelligent enough to spot the @file in the quotes and replace that will the value of @file.

Upvotes: 1

Related Questions