Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor Syntax - using model property inside Url.Content

I'm trying to figure out the proper way to write this using Razor syntax:

<div style="background: url(@Url.Content("~/images/@Model.ImageUrl"))">
</div>

I am using @Url.Content("") and need to use a Model property within the string but I can't figure out the proper way to do it.

like image 238
Dismissile Avatar asked Jan 23 '26 07:01

Dismissile


1 Answers

@ expressions contain normal C# code.
You need to perform ordinary string concatenation:

@Url.Content("~/images/" + Model.ImageUrl))
like image 93
SLaks Avatar answered Jan 25 '26 08:01

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!