Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Instead of redirect to a view after click on "Details" button, i need it to open in a popup, without leave my index

C#
<div class="container">
    <h2>Lista de Personagens</h2>
    @foreach (var item in Model)
    {

        <div class="col-md-3" style="margin-bottom:20px">
            <div class="thumbnail">
                <div class="img-responsive" style="margin-bottom:20px">
                    <img src="~/App_File/images/" height="300" width="240" />
                     <button type="button" onclick="AddThePopUpActionHere"></button>
                </div>
                <div class="caption" style="border-top:3px solid #808080">
                    <h5 style="font-family:'Comic Sans MS'">Nome: @item.PersonagemNome</h5>

                </div>
            </div>
        </div>
    }
</div>


What I have tried:

Already tried some javascript codes, but didn't worked.
Posted
Updated 18-Jul-19 8:55am

1 solution

HTML
@foreach (var item in Model)
    {

        <div class="col-md-3" style="margin-bottom:20px">
            <div class="thumbnail">
                <div class="img-responsive" style="margin-bottom:20px">
                    <img src="~/App_File/images/" height="300" width="240" />
                     <button type="button" onclick="showDetails(item.value)"></button>
                </div>
                <div class="caption" style="border-top:3px solid #808080">
                    <h5 style="font-family:'Comic Sans MS'">Nome: @item.PersonagemNome</h5>

                </div>
            </div>
        </div>
    }


In JavaScript you do something like:

JavaScript
function showDetails(item){
     alert(item);
}


Remember, each time through the loop, the dynamic item.value will be the current one. So there will be numerous buttons. The button will be connected to the item value.

First, try it with a String type property of the item then try it with some other property because if that is a complex object then the showDetails() function may not get the value you expect.
 
Share this answer
 
Comments
BillWoodruff 19-Jul-19 3:55am    
+5

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