Pass data-id="@Milestones.Code" to a modal

Asked

Viewed 351 times

2

My system should work as follows:

By clicking the button highlighted in red in the image below

inserir a descrição da imagem aqui

He opens this modal here:

inserir a descrição da imagem aqui

This already happens, but now I need to click on the first image, it takes the data-id="@milestones.Codigo" and save in the field CodigoMilestone.

Button that calls the modal Activity:

<button class="btn btn-default AddAtividade" data-id="@milestones.Codigo"><i class="glyphicon glyphicon-plus"></i></button>

Script that opens the modal:

$(document).ready(function () {

$(".AddAtividade").click(function () {
    $("#modal").load("AddAtividade", function () {
        $(".modal").modal();
    })
}); 
})

How can I do that?

  • 1

    Must be something like this: var id = $(this).attr("data-id");

1 answer

2


I could do something like this.

$(document).ready(function () {

$(".AddAtividade").click(function () {

    var codigoMilestone = $(this).attr("data-id");

    $("#modal").load("AddAtividade", function () {

        $("#meuInputId").val(codigoMilestone);

        $(".modal").modal();
    })
}); 
})
  • Thanks, it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.