Hi everyone. I’m new to umbraco, and learning by doing and reading documentation.
I currently don’t have any custom controllers yet. I am grabbing & parsing the data from CMS to the Views by setting up something like the below at the top of every .cshtml file
@{
var allDataToDisplay = Model.Root().Descendants(ContentType.SomeDocType).ToList();
}
I realise this may not be ideal.
I want to pass data from the CMS (i.e. allDataToDisplay variable) to some javascript at the bottom of .cshtml to render/reload the page in some way. The original intent is to store query string via javascript to create a multi-dropdown list sort.
@foreach (var item in allDataToDisplay)
{
<a href="check(JSON.Encode(item.Name.ToString()))>Trigger alert </a>
}
<script type="text/javascript">
function check(cmsValue){
alert(cmsValue);
}
</script>
I apologise in advance if this is not the right question to ask, but how do I pass values from the CMS to javascript on Umbraco please?
Thank you so very much for reading and for your time.
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/101032-passing-values-from-view-cshtml-to-javascript