开发者

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 y开发者_开发问答our 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.


How about this?

@(ViewData("photo")).jpg

Edit: And with the dynamic ViewBag:

@(ViewBag.photo).jpg


Adding as answer:

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


You could always try:

@string.concat(ViewData("photo"),".jpg")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜