Ad

Pass Model Data To Javascript Function

I have this model @model WebApplication1.Models.Person which has an Id data. I want to pass Id to a javascript function via <a href="#" onclick=myFunction(idGoesHere)>.

I tried putting @Model.id or passing the value of @Model.id to another variable, but still it doesn't work. Any help would be appreciated.

Ad

Answer

Your call to your JS function will look like this:

<a href="#" onclick="myFunction('@Model.id')"> </a>

This will send the current id in concern to your JS function.

Ad
source: stackoverflow.com
Ad