Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Add click event through Html.PropertyFor method

ZZ
ZZ
Vote:
0

Hi,

We are using @Html.PropertyFor(m => m.LeftColumnLinks) for generating links. LeftColumnLinks property is of type LinkItemCollection.

Is it possible to add click event on the generated anchor tag ?

#302769
Jun 01, 2023 7:49
Vote:
1
#302773
Edited, Jun 01, 2023 8:43
Vote:
0

Html.PropertyFor should create unique id that you can 
> document.getElementById("uniqueId").addEventListener("click", myJsFunction);

#302774
Jun 01, 2023 8:45
Scott Reed - Jun 01, 2023 8:51
JS is an option, although I don't believe there's any unique IDs added on (unless custom) when rendered in the non edit view but you can pass an id value or class as a parameter the Html.PropertyFor attributes collection
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.