Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC3 Razor @string dot problem

With the MVC3 Razor synax, one may render a string like so

@ViewData("photo")

My problem is: How can I append a dot to the above code. The following will result in a "Public member 'jpg' on type 'String' not found.":

@ViewData("photo").jpg

I've tried the following code but does not produce my intended result:

@ViewData("photo") .jpg
@ViewData("photo"):.jpg
@ViewData("photo") & ".jpg"

Thanx for advance for your help. And please dont advice me to append the "jpg" in the controller's code like so:

ViewData("photo") = "filename.jpg"

I've searched the Net for the same problem but found none, not even something

similar. By the way, I'm using VB.net.

like image 203
Arvin Avatar asked Apr 16 '11 06:04

Arvin


2 Answers

How about this?

@(ViewData("photo")).jpg

Edit: And with the dynamic ViewBag:

@(ViewBag.photo).jpg
like image 127
Jesper Palm Avatar answered Nov 07 '22 17:11

Jesper Palm


Adding as answer:

@(ViewData("photo") + ".jpg")

like image 21
manojlds Avatar answered Nov 07 '22 17:11

manojlds