loveforfire33
loveforfire33

Reputation: 1120

@HtmlRaw One Word

im trying to use razor to generate a url like this

<img id="currentPic" src="/content/img/@Html.Raw(Model.user.defaultImage).png" />

but the .png bit is being added to the @htmlraw syntax and is not compiling. I know i need to tell the page that @htmlraw is over. I tried using ; which worked - but the ; was also displayed in the string when displayed.

How can i get it so it would display like this. When Model.user.defaultImage = random1

<img id="currentPic" src="/content/img/random1.png" />

thanks

Upvotes: 0

Views: 70

Answers (4)

Andy T
Andy T

Reputation: 9901

This feels like a hack, but works:

<img id="currentPic" src="/content/img/@Html.Raw(Model.user.defaultImage + ".png")" />

Upvotes: 0

Satpal
Satpal

Reputation: 133433

I think you don't need Html.Raw, just use

<img id="currentPic" src="/content/img/@(Model.user.defaultImage).png" />

Upvotes: 0

JDwyer
JDwyer

Reputation: 844

Try @{Html.Raw(Model.user.defaultImage)}

Upvotes: 0

Matt Bodily
Matt Bodily

Reputation: 6413

try adding a new set of parenthesis

<img id="currentPic" src="/content/img/@(Html.Raw(Model.user.defaultImage)).png" />

Upvotes: 1

Related Questions