Home > Blockchain >  always getting the value of first item in list when posting
always getting the value of first item in list when posting

Time:01-07

the [email protected] is always the value of first item in list and if any one can help me with sending the id directly to modal i will be thankfull

    @foreach (var item in Model.GetContracts)
    {   
<tr>
    <td>@item.Plate</td>
    <td>@item.Cname</td>

    <td>@item.CheckIn.ToString("dd/MM/yyyy")</td>
    <td>@item.CheckOut.ToString("dd/MM/yyyy")</td>
    <td>@item.Price</td>
    <td>@item.Paid</td>
    <td>@item.Deposit</td>
    <td>@item.Note</td>
    <td>@item.Id</td>
       
        
    <td><Button type="button"  data-toggle="modal" data-target="#Returned" onclick="getId">إغلاق العقد</Button></td>

    <td><a  asp-page="Returned" asp-route-Id="@item.Id">إغلاق العقد</a></td>
    <td><a  asp-page="CheckOut" asp-route-Id="@item.Id">تجديد</a></td>

    <td>
        <div  id="Returned" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
            <div  role="document">
                <div >
                    <div >
                        <h5  id="exampleModalLongTitle"></h5>
                        <button type="button" cl ass="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div >
                        <form method="post" asp-page-handler="Returned" asp-route-id="@item.Id">
                            @item.Id



                            <input type="date" asp-for="@Model.Update" />

                            <input type="submit"  />
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </td>

        
</tr>

    }

any help please even if any server side lang may help

CodePudding user response:

Your modal actually passed the correct id, but the button does not trigger correct modal because the data-target is always the same. That is why you always get the modal with the first id.

Add an index to specify the modal id:

@{  int i = 0; }   //add this...
@foreach (var item in Model.GetContracts)
{
    <tr>
        <td>@item.Plate</td>
        //....
        <td>@item.Id</td>
                                                            //change here...
        <td><Button type="button"  data-target="#Returned_@i" data-toggle="modal" onclick="getId">إغلاق العقد</Button></td>    
        <td>
                                     //change here...
            <div  id="Returned_@i" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                <div  role="document">
                    <div >
                        <div >
                            <h5  id="exampleModalLongTitle"></h5>
                            <button type="button" cl ass="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div >
                            <form method="post" asp-route-id="@item.Id">
                                @item.Id            
                                <input type="date" asp-for="@Model.Update" />  
                                <input type="submit"  />
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </td>
    </tr>
    i  ;    //add this...
}
  •  Tags:  
  • Related