0

I am creating a dynamic button while listing the data in the function below. When the button is clicked, I want the ID to go as a crypto string, but I could not get the item value.

  function ProductListToDisplay(data) {
        var content = "";

        $(data).each(function (indx, item) {
           content += '<tr>';
           content += '<a class="mr-2" href="/CPY/CpyDoc_Dokumanlar/Delete?id=@Uri.EscapeDataString(CryptoProvider.Encrypt(item.id.ToString()))"></a> </span></td>';
           content += '</tr>';
    
       });
    }
    

MeralTd
  • 1
  • 3
  • At the time when button is renders add a javascript function to be called and Pass the Id as a parameter to the function – Kaushikkumar Halvadia Mar 16 '22 at 07:08
  • What error are you getting on your browser console while performing this action? Can you try this way: `` – Rahul Sharma Mar 16 '22 at 08:08
  • I tried it didn't work I get the **"The name 'item' does not exist in the current context"** error @RahulSharma – MeralTd Mar 16 '22 at 09:21
  • @MeralTd Your `item` is a JS variable. Try removing `ToString` from it. You basically need to access your `js` variable inside the c# method? – Rahul Sharma Mar 16 '22 at 09:23
  • @RahulSharma Yes I need to access js variable inside c# method – MeralTd Mar 16 '22 at 09:54
  • @MeralTd Well, the opposite is definitely possible but according to this answer: https://stackoverflow.com/questions/39900614/use-javascript-variable-in-asp-net-mvc-razor-syntax and https://stackoverflow.com/questions/28317182/how-to-pass-a-value-to-razor-variable-from-javascript-variable, you can not use Javascript variables in C#, because javascript code is available only after C# / Razor is rendered – Rahul Sharma Mar 16 '22 at 10:16

0 Answers0