phoenixAZ
phoenixAZ

Reputation: 421

.net Razor render concatenated text with no space

I have:

 @:<img src="@Url.Content("~/content/images/lesson_icon/")@mi.LessonId .png" />

But it renders as ...lesson_icon/d40d2ff2-d06b-4fd8-80a0-0ed31bbc04eb%20.png

How can I get rid of the %20 in front of .png ?

Upvotes: 4

Views: 3175

Answers (2)

Benjamin RD
Benjamin RD

Reputation: 12034

You can send a string with the complete link, for example:

string path = "../content/images/lesson_icon/"
string link = path + mi.LessonId + ".png";

And send that in the model, or you can try:

@{string png = ".png"}
@:<img src="@Url.Content("~/content/images/lesson_icon/")@mi.LessonId + @png />

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039130

You have a space before your file extension that you should remove there:

<img src="@Url.Content(string.Format("~/content/images/lesson_icon/{0}.png", mi.LessonId))" />

or if you are using Razor v2 you could try that:

<img src="~/content/images/lesson_icon/@(mi.LessonId).png" />

Upvotes: 10

Related Questions