0

How I can make it work:

@foreach (var alert in Model.AlertsRelatedToBrand)
 {
     <li class="notifications-row">
         <div class="notifications-icon notifications-icon-alert">&nbsp</div>
         <div class="notifications-text"><a>@alert.Title</a></div>
         <a href="#" class="notifications-dismiss" onclick="onHideAlertClick(@alert.Id)">x</a> // here is problem
     </li>
}

I want to send id of each alert to function if item was clicked.

4
  • Error message would be very helpful.. Commented Jul 19, 2016 at 13:16
  • is the id an int or a string? Commented Jul 19, 2016 at 13:18
  • Try messing around with the quotes... onclick="onHideAlertClick('@alert.Id')" or onclick='onHideAlertClick(@alert.Id)' etc etc Commented Jul 19, 2016 at 13:20
  • What does your onHideAlertClick() function look like? Commented Jul 19, 2016 at 13:21

1 Answer 1

1

Your code appears correct as the use of @alert.Id should output the value into your existing onHideAlertClick() function :

onclick="onHideAlertClick(@alert.Id)"

It's worth noting that if your Id property is an integer, you may want to try wrapping the parameter within single quotes to pass it along as a string as seen below :

onclick="onHideAlertClick('@alert.Id')"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.