Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can we assign a value to a tempdata in an event like click in Jquery.
If yes ,How store this in variable ?

trying like this but not get a value ,

please help me,

What I have tried:

var ptran1 = $('@TempData["m_pran"]').val().trim();

or
var ptran2 = ('@TempData["m_pran"]');


alert(ptran1)

alert(ptran2)
Posted
Updated 24-Mar-19 3:12am
Comments
David_Wimbley 23-Mar-19 3:34am    
If you are trying to get the value from TempData, off the top of my head, var ptran2 = ('@TempData["m_pran"]'); shoudl work (i think) so you may need to debug your application to see why there is nothing in TempData.

If you are trying to save a value from jQuery to tempdata you will need to perform an ajax call to the back end to set that value.
sayli1995 23-Mar-19 23:46pm    
thanks sir

1 solution

try this,

On a controller set,
TempData["key"] = "XYZ";

And on the view use follwing code,

var val = '@TempData["key"]'
alert(val);//it will alert message XYZ
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900