This project is read-only.

Formating a string

Topics: Customizing Orchard, General
Mar 1, 2013 at 11:15 AM
Hi There

This is quite an easy one but I am struggling with it.
I have a view that gets data from a model. I have manually added images to the Media folder that is name by the code related to the record.

How do I format the string to display the image.

Required output

<img src="~/media/default/dealers/thumb/dealers_1234.Jpg width="220" height="170" alt="Image" />

What Im trying to do is something like this but the below code is obviously not working

<img src="~/media/default/dealers/thumb/dealers_@dealer.dealercode.jpg width="220" height="170" alt="Image" />

Mar 2, 2013 at 1:44 AM
var mySrc ="~/media/default/dealers/thumb/dealers_" + dealer.dealercode + ".jpg";

<img src='@mySrc' width="220" height="170" alt="Image" />
Note: Hardcoding in ../default/... means it will only work on sites that do not use multi-tenancy. With multi-tenancy "default" is replaced by tenant name. I cannot remember how to get this off the top of my head but I'm sure a quick google search will save the day. However, I am too lazy for such a task.