Thank you
are not very practical to write controllers, however it is not a problem to get the contents, the problem is the passage of the id, it is not possible in querystring because the href event is inhibited so you can only go in javascript, I miss how to pass id obtained in javascript, to be able to put it in a foreach or to get the right contents of the different nodes.
Please help me !!
thank you
You are missing the basic concept that the razor code runs server side before the JavaScript. The only way I can think of this working without some kind of api call is to load the contents into a JSON array using razor, then look up the array when you click on an element. You could store the id of the element in a data attribute if you're not doing it already.
I'm guessing you're swapping an image and content out depending on the element clicked? Is that right?
This is possible without ajax if you have a limited number of options you could output them all and hide and show the right one depending on the click. I wouldn't suggest you do this if there are more than 40-50 odd as the page size would start to be a problem.
This would avoid the need for a controller to return the ajax but Paul's suggestion is the cleaner solution. Let us know how many different IDs there are likely to be and I can skeleton you out a quick solution.
function javascript and razor
Hi I have this function that works well:
it gives me the right id at the click.
then I have this script:
it returns me the right contents belonging to the node with id 1073.
The question is: how do I assign the value returned by the javascript function to the variable p Thanks!
You could use an api controller to get that content, which you could call from your JavaScript.
Thank you are not very practical to write controllers, however it is not a problem to get the contents, the problem is the passage of the id, it is not possible in querystring because the href event is inhibited so you can only go in javascript, I miss how to pass id obtained in javascript, to be able to put it in a foreach or to get the right contents of the different nodes. Please help me !! thank you
You are missing the basic concept that the razor code runs server side before the JavaScript. The only way I can think of this working without some kind of api call is to load the contents into a JSON array using razor, then look up the array when you click on an element. You could store the id of the element in a data attribute if you're not doing it already.
Hi Crisweb,
Can you start from the requirement?
I'm guessing you're swapping an image and content out depending on the element clicked? Is that right?
This is possible without ajax if you have a limited number of options you could output them all and hide and show the right one depending on the click. I wouldn't suggest you do this if there are more than 40-50 odd as the page size would start to be a problem.
This would avoid the need for a controller to return the ajax but Paul's suggestion is the cleaner solution. Let us know how many different IDs there are likely to be and I can skeleton you out a quick solution.
Steve
Sorry but my mind is stuck !!!
The idea was this:
I find the images and send 'id unfortunately not in query string
and it works
@{ var portof1 = CurrentPage.AncestorOrSelf(1).Descendants("portfolio");} @foreach (var port1 in portof1.Where("visible")) {
}
I resume the id
and it works
here I do not know what to do !!!!
with fixed id works well
@{ int p = 1073;}
@Umbraco.Content(@p).portTitolo
@Umbraco.Content(@p).portTesto
Please help me
Hi,
Sorry - but that makes no sense to me! What are you trying to do?
Steve
Hello I'm trying to populate the variable @{int p = } with the result of javascript. Am I wrong to do it?
Andrea
is working on a reply...