mehwish
mehwish

Reputation: 199

MVC escape razor output

I have been trying to escape razor code so that is outputs the category in middle of the file name.

<div class="headerpost" style='background-image: url(~/CategoryImages/'@Model.Category'.jpg);'>

So that it appears like /CategoryImages/Orders.jpg in the background-image style. I have tried several escape characters & "" + none of them work.

Upvotes: 1

Views: 101

Answers (2)

user3559349
user3559349

Reputation:

The format need to be

<div class="headerpost" style='background-image: url(~/CategoryImages/@(Model.Category).jpg);'>

Upvotes: 1

Anirudha Gupta
Anirudha Gupta

Reputation: 9289

<div class="headerpost" style="background-image: url('~/CategoryImages/@(Model.Category).jpg');">

Check the single quotes in this code, it should be on whole URL part.

Upvotes: 0

Related Questions