0

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.

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Ya got it boss , Thank you
@Aniket close vote would be way more appropriate... There is not much value in repeating the same statement many times, especially if you are not trying to farm rep.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.