OT_DEV
OT_DEV

Reputation: 171

~ operator in Mvc-5

I know this question has been asked number of times but I am unabe to make out from the answers given earlier. I am trying to set the background image for all the views in _layout.cshtml file. I have tried two versions for the same 1) body style="background-image: Url('~/Content/Texture.png');" It tries to look at this path http://localhost/SU-Tour/~/Content/Texture.png whereas it should look into http://localhost/SU-Tour/Content/Texture.png I am guessing it is not recognizing the tilde character.

2) body style="background-image: @Url.Content("~/Content/Texture.png");" This method doesn't create any error but the image property is not set to the body tag when i inspect the element under chrome.I am clueless about this one.

Please help me resolve this.

Upvotes: 2

Views: 183

Answers (1)

Lloyd
Lloyd

Reputation: 29668

It should be:

style="background-image: url('@Url.Content("~/Content/Texture.png")');"

So that it ends up as:

style="background-image: url('/SU-Tour/Content/Texture.png');"

It can get a bit confusing when you start mixing Razor with CSS.

Upvotes: 3

Related Questions