Change ID passed to Modal when changing dropdown menu option on razor page

Viewed 10

I have a page to edit some information, on this page I have a button which opens a modal, I create the dropdown as so,

<label class="select" style="width: 100% !important">
    @(Html.DropDownList("InteractingDrugId", Model.AllSubstances, new { @class = "select2 form-control",
              @style = "width: 50% !important",
              @data_placeholder = "Type drug to find" })
  )
</label>

The button for the modal uses Modal.ID to set the items inside the modal.

<a class="btn btn-warning edit-interaction-ref" href="javascript:void(0)" data-id="@(Model.ID)" data-toggle="tooltip" title="Edit References">
      <i class="fas fa-link"></i>
      References
</a>

All works fine, and the modal loads correctly with the correct info in, but if I change the option in the dropdown to a different item, the data in the modal stays the same as the one initially loaded on the page.

When I change the option in the dropdown I also want the Modal.ID to change.

Is this possible?

1 Answers

You can try to use js to change data-id when the selected value is changed,but you cannot change Model.ID directly,because it is a c# variable:

<script>
        $("#InteractingDrugId").change(function() {
            $("a.edit-interaction-ref").attr("data-id", $("#InteractingDrugId").val());
        })
</script>
Related