ASP MVC Passing value into modal window

后端 未结 3 914
旧时难觅i
旧时难觅i 2021-01-22 13:04

I have this view with a modal window. When I click to open the modal window, I\'d like to pass the parameter item.InstrumentId into the modal window so that I can c

3条回答
  •  情歌与酒
    2021-01-22 13:32

    You currently generating a modal for each item in your collection but giving it an id="myModal" which is invalid html and means data-target="#myModal" will only ever open the first one. Move the modal outside the loop so your create only one (and also remove the

    element which also has the same id attribute)

    Then change the button html to

    and change the html in the modal to

    Instrument: Details
    

    Then change the script to

    $(document).on("click", ".open-dialog", function() {
        $('#details').attr('href', $(this).data('url')); // update the links url
    })
    

    Side note: You will probably want to do something similar with Checked: @item.Checked in the modal

提交回复
热议问题