Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<body>
    <div class="container h">
        <h2><b>Machines</b></h2>
        
        <div class="row" style="margin-top:10px;margin-left: 10px;">
            @{foreach (System.Data.DataRow sp in ViewBag.view.Rows)
              { 
                <div class="col-sm-3 img" >
                <h5><p style="margin-left:50px">@sp["Model_Number"].ToString()</p></h5>
                <img onmouseover="bigImg(this)" onmouseout="normalImg(this)" src="@sp["Image"].ToString()" onclick="handleClick(this)" style="height:180px;width:170px;border:groove;border-width:2px;border-color:yellow"/>
                <p style="margin-left:30px;" >@sp["Manufacture"].ToString()</p>
                <input   name="id" value="@sp["Machine_Id"].ToString()"/>
                 
           </div>}}
              
               
                  

            
</div>
</div>
</body>


What I have tried:

i am trying to get id of image on click event of image..how can i do that'
Posted
Updated 24-May-16 21:01pm
Comments
Karthik_Mahalingam 25-May-16 2:04am    
looks the img tag doesn't have id attribute.
vishal goyal 25-May-16 2:13am    
i want that when i click on image..i want to show that particular image info on another page...so for that i need to pass id of that image in action method.
so how can i get id of that image?
Karthik_Mahalingam 25-May-16 2:25am    
the code which you have posted, doesnt have id attribute, so you cant get the id...
Karthik_Mahalingam 25-May-16 4:47am    
does the Table has Id column?
vishal goyal 27-May-16 6:33am    
no

1 solution

Try setting id of your image. then in handleClick method you can get your current image id.

Razor
@{int i = 0;}
@{foreach (System.Data.DataRow sp in ViewBag.view.Rows)
        { 
                <div class="col-sm-3 img" >
                <h5><p style="margin-left:50px">@sp["Model_Number"].ToString()</p></h5>
                <img id="Img_@i" onmouseover="bigImg(this)" onmouseout="normalImg(this)" src="@sp["Image"].ToString()" onclick="handleClick(this)" style="height:180px;width:170px;border:groove;border-width:2px;border-color:yellow"/>
                <p style="margin-left:30px;" >@sp["Manufacture"].ToString()</p>
                <input   name="id" value="@sp["Machine_Id"].ToString()"/>
                i++;
                 
           </div>
  }}


Good luck.
 
Share this answer
 
v3
Comments
Raje_ 25-May-16 3:09am    
I am sorry I am not able to paste the code correctly. It seems there are some issue submitting answer. Eg. I am writing @{foreach but it shows @{}oreach. :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900