문제

I am currently working in a project with c# and umbraco CMS. And now im facing some issues one of them is that I don't know how to get the media ID dynamically, please take a look ID COMES FROM UMBRACO

Media file = new Media(3557);

string url = file.getProperty("umbracoFile").Value.ToString();
string teste = file.getProperty("impressions").Value.ToString();
if (teste == "" || teste == null) { teste = "0"; }
int count= Convert.ToInt32(teste);
file.getProperty("impressions").Value = count+1;

file.Save();

Do you see that 1st line ? Media file= new media(id)? I want to get this id dynamically and I will explain why. I have this handler in order to get the banner clicks on the site. I have 4 images and I want to have a count for how many times the client clicks on them. So for that I can't have the id = 3557 , I need to get the id of the image dynamically.

도움이 되었습니까?

해결책

I assume you are using an event handler, something like:

protected void imgMyMedia_OnClicked(object sender, EventArgs e) { your code }

In that case, you can cast the sender object to your control type, and read any parameter set there. I recon it would be something like this:

MediaControl myMedia = (MediaControl)sender; int ID = myMedia.MediaId;

or something similar. I am not familiar with the umbraco code and can not be as precise, but this should be about right.

다른 팁

When you render the image in the first place you want to put the image id in a data attribute so your html will be something like:

<img src="/media/someimage.jpg" data-id="someMediaIdHere" alt="alt" title="title" />

Then use that when your javascript picks up the onclick event, then you can pass the image id to the server side and do your tracking.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top