sangeetha k

sangeetha k

  • NA
  • 207
  • 51.6k

How to redirect to an actionmethod which has a parameter

Apr 4 2018 3:47 AM
button is the icon link in the table:
  1. <tbody>  
  2. @foreach (var item in Model)  
  3. {  
  4. <tr>  
  5. <td class="edit1" scope="row">@Html.DisplayFor(model => item.Empid)</td>  
  6. <td class="edit">@Html.DisplayFor(model => item.Empname)</td>  
  7. <td class="edit">@Html.DisplayFor(model => item.Designation)</td>  
  8. @*<td>  
  9. <img src="@Url.Content(@item.Empimage)" alt />  
  10. </td>*@  
  11. <td class="edit">  
  12. @{  
  13. var base64 = Convert.ToBase64String(item.ImageData);  
  14. var imagesrc = string.Format("data:image/jpeg;base64,{0}", base64);  
  15. <img src='@imagesrc' style="max-width:100px;max-height:100px;" />  
  16. }  
  17. </td>  
  18. <td class="edit">@Html.DisplayFor(model => item.Salary)</td>  
  19. <td class="edit">@Html.DisplayFor(model => item.Email)</td>  
  20. <td class="edit">@Html.DisplayFor(model => item.Department)</td>  
  21. <td>  
  22. <a href="#" data-id="@item.Empid" id="btnDelete" class="Delete" role="button" >  
  23. <span class="glyphicon glyphicon-trash"></span>  
  24. </a></td>  
  25. </tr>  
  26. }  
  27. </tbody>  
using normal button click:
  1. $(document).ready(function () {  
  2. var empid = $('.Delete').attr('data-id');  
  3. $("#EmpTable").on('click','.Delete',(function () {  
  4. debugger;  
  5. var url = '@Url.Action("DeleteEmployee", "Employee", new { id = empid })';  
  6. var newurl = url + "empid" + empid;  
  7. window.location.href = newurl;  
  8. }));  
or via ajax call:
  1. $(document).on('click''#btnDelete'function () {  
  2. var empID = $(this).attr('data-id');  
  3. debugger;  
  4. $.ajax(  
  5. {  
  6. type:'GET',  
  7. url: '<%=Url.Action("DeleteEmployee","Employee")%>',  
  8. data: "{ EmployeeID:'" + empID + "'}",  
  9. success: function (data) {  
  10. alert('deletion sucess');  
  11. }  
  12. });  
both the things are not hitting tell me where i am wrong. Pls 

Answers (6)