Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have the below code which is using Javascript and Razor. The below code is within the Javascript parameter which is working
foreach (var childPage in Model.Children.Where("Visible")) { var CustomerAndImage = @childPage.CustomerName + '<img src="' + @Model.MediaById(@childPage.image).umbracoFile +'" alt="Porcelain Factory of Vista Alegre" height="115" width="83">'; <text>['@CustomerAndImage'],</text> }
I'm trying to embed an image to be part of the variable CustomerAndImage but whenever i add 'Too many characters in character literal"
Hi J,
This because you are single quotes. In c# (Razor) this can only contain one character. For full strings you need to surround it with double quotes :
foreach (var childPage in Model.Children.Where("Visible")) { var CustomerAndImage = @childPage.CustomerName + "<img src=\"" + @Model.MediaById(@childPage.image).umbracoFile +"\" alt=\"Porcelain Factory of Vista Alegre\" height=\"115\" width="83">"; <text>['@Description'],</text> }
Dave
Hi Dave - thanks
I did that, added and an extra \ where it was missed off but instead of the img tag being embedded its just displaying the code as text? Any idea?
Can you post your entire code. This is just a few lines. Can not see where it is going wrong
I've changed some of it whilst refactoring. Please see below
@inherits umbraco.MacroEngines.DynamicNodeContext
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript"> var MapLocations = [ @if (Model.Children.Where("Visible").Any()) { var naviLevel = Model.Children.Where("Visible").First().Level; foreach (var childPage in Model.Children.Where("Visible")) { var LatLng = @childPage.LatLng; var Customer = @childPage.CustomerName; var Image = "<img src=\"" + @Model.MediaById(@childPage.image).umbracoFile + "\" alt=\"test\" height=\"115\" width=\"83\">"; <text>['@Customer' + '@Image', @LatLng],</text> } } ];
Can you do this :
<text>['@Customer' + '@Html.Raw(Image)', @LatLng],</text>
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Razor help to embed image
I have the below code which is using Javascript and Razor. The below code is within the Javascript parameter which is working
I'm trying to embed an image to be part of the variable CustomerAndImage but whenever i add '
Too many characters in character literal"
Hi J,
This because you are single quotes. In c# (Razor) this can only contain one character. For full strings you need to surround it with double quotes :
Dave
Hi Dave - thanks
I did that, added and an extra \ where it was missed off but instead of the img tag being embedded its just displaying the code as text? Any idea?
Can you post your entire code. This is just a few lines. Can not see where it is going wrong
I've changed some of it whilst refactoring. Please see below
@inherits umbraco.MacroEngines.DynamicNodeContext
Hi J,
Can you do this :
Dave
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.