sanju kumar

sanju kumar

  • NA
  • 90
  • 7.6k

How to pass jquery value into server side code in MVC

Mar 15 2019 12:51 AM
I have this function in App_Data/CommonFunction
public static string Encrypt(string clearText)
{
string EncryptionKey = "MAKV2SPBNI99212";
byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(clearBytes, 0, clearBytes.Length);
cs.Close();
}
clearText = Convert.ToBase64String(ms.ToArray());
}
}
clearText = clearText.Replace("+", " ");
return clearText;
}
And Now in Cshtml page i have
<select class="" data-val="true" id="DDlPagingValID" name="DDlPagingValID"><option value="">Select record size</option>
<option value="1">50</option>
<option value="2">100</option>
<option selected="selected" value="3">500</option>
<option value="4">1000</option>
</select>
<script>
$(document).ready(function () {
$("#DDlPagingValID").on('change',function(){
var Value="";
Value=$("#DDlPagingValID :selected").text();
/* I want to Encrypt this selected value from server side function*/
/*i want to pass selected value form jquery into razor syntax */
var [email protected](Value);
/*I am not able to use jquery value in server side function */
});
})
</script>

Answers (5)