0

I have some code in Index view

@foreach (var item in Model){
<tr><td>......</td>
    <td><button class="success" data-toggle="modal" data-target="#detailsModal" >details</button>
        <div class="modal fade" id="detailsModal" tabindex="-1" role="dialog" aria-labelledby="detailsModalLabel" aria-hidden="true">
             @{Html.RenderPartial("_Details", item);}
        </div></td></tr>}

but after click my button on different rows, popup show always first item of database. How can I change it?

Controller

        public ActionResult Details(int? id)
    {
        DBase dbase = new DBase();
        dbase = db.DBase.Find(id);
        return PartialView("_Details", dbase);
    }

1 Answer 1

1

You have multiple modals declared in your HTML with same ID due to your foreach loop.

So it only uses the first modal element it found. To fix this give each of your modal a unique ID.

So you would change data-target="#detailsModal" and id="detailsModal" by adding index to it so it would be like id="detailsModal-1" etc

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.