简体   繁体   中英

How to access value to encrypt the value in c# using jQuery in mvc

In jQuery I have a function that gets an id that i want to encrypt the date in mvc method, in mvc we can access the coding in html view page itself. in that how to add jQuery function data in that one method

My jQuery function

function Redirect(id) {

    var propertyidconvert = '@Utility.Utilities.Commonfunction.Encrypt(id, "PropertyId")';
        alert(propertyidconvert);

}

I have a C# method to encrypt the data, but I am unable to add id value, showing error.

You cannot run C# methods during JavaScript runtime. By the time your JS runs, the view has already been built and rendered by C# and is no longer in the scope of .NET MVC.

To accomplish this, you either have to make an AJAX request back to the server and then receive the encrypted response in JS, or encrypt your data directly in JS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM