Dynamically changing background - Razor and JavaScript
Hi guys and girls
I have spent too many hours looking at this code now.. Can anyone help me see what i am doing wrong here.
I need this piece of code to work - and it is so close - however, the content that I feed to the imageUrls array, doesnt have quotationmarks around them, so the code can't read them as real entries.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
if(Umbraco.TypedContentAtRoot().First().HasValue("vaelgMappe")){
var mappen = Umbraco.TypedContentAtRoot().First().GetPropertyValue("vaelgMappe");
var selection = Umbraco.Media(@mappen).Children;
var urlSelection = new List<string>();
foreach(var l in selection){
urlSelection.Add(l.Url);
}
var imageUrls = @String.Join(", ", urlSelection.ToArray());
<script type="text/javascript">
$(document).ready(function() {
$("body").backgroundCycle({
imageUrls: [@imageUrls],
fadeSpeed: 2000,
duration: 10000,
backgroundSize: SCALING_MODE_COVER
});
});
</script>
}
}
It is live on my development server here: http://dev.kravspecifikation.dk/ - you can see it if you inspect and open the last script of the tag.
Dynamically changing background - Razor and JavaScript
Hi guys and girls
I have spent too many hours looking at this code now.. Can anyone help me see what i am doing wrong here.
I need this piece of code to work - and it is so close - however, the content that I feed to the imageUrls array, doesnt have quotationmarks around them, so the code can't read them as real entries.
It is live on my development server here: http://dev.kravspecifikation.dk/ - you can see it if you inspect and open the last script of the tag.
I hope someone can help me!
Kind regards, Magnus Szatkowski
Hey Magnus,
Maybe you could add the quotes when you add the urls in your urlSelection list? Something like:
That way they should get through when you build your imageUrls array.
Hope it helps.
Cheers,
Michael.
Hi Magnus
Did you try to use JavaScriptSerializer?
Hope it will help.
Thanks,
Alex
Hey Alex and Michael,
Both good suggestions. However, Alex' code gets this results in this code being printed:
and Michaels code results in:
Do you have any idea if we can get rid of the """ or "'" and print the quoatation mark instead?
Kind regards,
Try using Html.Raw:
Cheers,
Michael.
Mangus, try to decode result:
Extreme programming with Michael and Magnus :)
Thank you guys!
I got Michaels code to work, but i am sure your's would work too Alex!
Thank you so much :)
Kind regards, Magnus
@Magnus: Great!
@Alex: Indeed ;-)
Cheers,
Michael.
Guys, have a great day! #h5yr
I love this community :-D
Great day to you too! #h5yr
Thanks and have a great day as well ;-) #h5yr
is working on a reply...