How to pass values to controller from Javascript code in MVC

后端 未结 3 459
一向
一向 2021-01-07 01:32

Actually I have a scenario like :

I am getting the values of checked records in GridView through Javascript. Now i need to send those values to controller for deleti

相关标签:
3条回答
  • 2021-01-07 01:43

    In your controller use this statement for retrieving the value: Request.Params["ID"]

    0 讨论(0)
  • 2021-01-07 01:50

    Consider the following example i am firing the script with a list value using for loop table data.

    <a href='#' class="gridEdit"  onclick="javascript:return DeleteServiceOut('@Model.EmployeeInformationList[i].GEmployeeGenInfoID.ToString()');"></a>  
    

    the function to pass values to controller from Javascript code in MVC

    <script>
     function DeleteServiceOut(GEmployeeId) {
    
            window.location = "/PMS/Payroll/ServiceOutAdd/ServiceOutDelete/" + GEmployeeId;
            return false;
        }
    
    </script>
    

    in to the controller

     public ActionResult ServiceOutDelete(string id, ServiceOutModels model)
            {
               // id will contailn the value of parameter
               // AS you want
                return View("ServiceOutViewDetails", model);
            }
    
    0 讨论(0)
  • 2021-01-07 02:03

    You can use AJAX inside your script.

    Something like this

    $.ajax({
             url: 'Your method in controller which will delete the records',
             type: 'POST',
             data: ' data which you want to send to controler ',
    });
    
    0 讨论(0)
提交回复
热议问题