How to send a parameter to the controller?

Sam

To send a parameter to a controller I use this :

<a class="btn btn-primary " @Html.ActionLink("Valider", "Create", new { iddemande = item.demandelist.id_demande   })></a>

To open a popup I use this:

   <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data- target="#exampleModalCenter" iddemande=item.demandelist.id_demande )>
               ADD
            </button>
            <!-- Modal -->
            <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true" data-url=" @Url.Action("Create","valideyds")">

My question is how do I send the parameter to the controller that opens the popup through a button?

I explain I want at the same time to send the parameter iddemande = item.demandelist.id_demande and open the popup with the same button.

Thanks for your help

Jerdine Sabio

You need to use ajax, this will send a request to a controller action asynchronously (without the need of redirect) at the same time you could open the modal based on the result.

First add a class to your button, I used modal-button and use data-property for assigning the value you want to pass. I used data-id;

<button type="button" class="btn btn-primary btn-sm modal-button" data-toggle="modal" data- target="#exampleModalCenter" data-id="@item.demandelist.id_demande">
   ADD
</button>

Add this to your @section scripts, in here we want to attach an event to the modal-button and get data-id and pass it to the controller via ajax.

<script>
   $(document).ready(function(){
      $(".modal-button").click(function(){
         // get data-id
         var id = $(this).data("id");

         // pass the id to controller
         $.ajax({
            type: "GET",
            url: "/ControllerName/ActionName",
            data: {iddemande:id},
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(result){
               alert(result);
            },
            error: function(err){
               alert(err);
            }
         });
      });
   });
</script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to send parameter to a GET API in another controller

From Dev

how to send image data through ajax as a parameter to spring controller

From Dev

How Send parameter in controller to view in Laravel 8 Mail

From Dev

Send Parameter to Controller in Routes Laravel

From Dev

How to send screenshot to controller?

From Dev

How to send params to controller

From Dev

mvc5 razor send parameter to controller

From Dev

angularJS send parameter from template to controller

From Dev

Send parameter from html to method in controller

From Dev

send parameter to controller vueJS and laravel 8

From Dev

How to send parameter by view

From Dev

how to send datatype as a parameter

From Dev

How can I send the dropdown value on selection to pass as a parameter to another function within the same controller; angular

From Dev

How to send Javascript map as a parameter from lightning component to Apex server controller?

From Dev

How to send controller action in url parameter in Asp.net Web Api?

From Dev

How to send Checkbox checked Values to Formcollection Parameter in controller from aspx view

From Dev

How to securely send data to the controller?

From Dev

how send table content to controller

From Dev

How send id Company in the controller?

From Dev

How to send a data parameter to a component?

From Dev

How to send method name as parameter

From Dev

how to send parameter in ajax call

From Dev

How to send datetime parameter to WCF

From Dev

How to send a post request with parameter?

From Dev

How send and receive a enum parameter?

From Dev

how to pass model as parameter to controller

From Dev

How to pass parameter to controller function

From Dev

Send parameter from view to controller via link in Grails

From Dev

Send Html as parameter from javascript to asp.net mvc controller

Related Related

  1. 1

    How to send parameter to a GET API in another controller

  2. 2

    how to send image data through ajax as a parameter to spring controller

  3. 3

    How Send parameter in controller to view in Laravel 8 Mail

  4. 4

    Send Parameter to Controller in Routes Laravel

  5. 5

    How to send screenshot to controller?

  6. 6

    How to send params to controller

  7. 7

    mvc5 razor send parameter to controller

  8. 8

    angularJS send parameter from template to controller

  9. 9

    Send parameter from html to method in controller

  10. 10

    send parameter to controller vueJS and laravel 8

  11. 11

    How to send parameter by view

  12. 12

    how to send datatype as a parameter

  13. 13

    How can I send the dropdown value on selection to pass as a parameter to another function within the same controller; angular

  14. 14

    How to send Javascript map as a parameter from lightning component to Apex server controller?

  15. 15

    How to send controller action in url parameter in Asp.net Web Api?

  16. 16

    How to send Checkbox checked Values to Formcollection Parameter in controller from aspx view

  17. 17

    How to securely send data to the controller?

  18. 18

    how send table content to controller

  19. 19

    How send id Company in the controller?

  20. 20

    How to send a data parameter to a component?

  21. 21

    How to send method name as parameter

  22. 22

    how to send parameter in ajax call

  23. 23

    How to send datetime parameter to WCF

  24. 24

    How to send a post request with parameter?

  25. 25

    How send and receive a enum parameter?

  26. 26

    how to pass model as parameter to controller

  27. 27

    How to pass parameter to controller function

  28. 28

    Send parameter from view to controller via link in Grails

  29. 29

    Send Html as parameter from javascript to asp.net mvc controller

HotTag

Archive