Reputation: 2589
I need to pass a param to the image onclick event. I know how to do it using a script and the controller, but I would like to know if it can be done directly in the view ? I've searched the SO and tried some examples but nothing worked so far.
@{string test = "kkkk";}
<img onclick="alert('' + @test + '')" />
<img onclick="alert(@test)" />
@{string test = "alert('kkkk')";}
<img onclick="alert(@test)" />
Upvotes: 0
Views: 988
Reputation: 824
this works perfect
@{string test = "kkkk";}
<img src="" onclick="alert('@test')" />
as @Çöđěxěŕ mentioned, here is the update: The reason why this solution works, op has not used single quotation marks around the var @test.
Upvotes: 2
Reputation: 142
This will give you an alert with kkkk
</span>@{string test = "kkkk";}
<img onclick="alert('@test')" />
Upvotes: 2