Click here to Skip to main content
14,039,595 members
Rate this:
Please Sign up or sign in to vote.
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();

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


Updated 24-Mar-19 3:12am
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190425.1 | Last Updated 24 Mar 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100