Hi
I just want to use tempdata value from a custom method but unable to do.
please help me.
here i am assigning value
public void abc(){
TempData["PhoneVarificationMissing"] = "Yes";
}
Here I want to access
public ActionResult kkk()
{
aaa obj=new aaa()
obj.abc();
var a=TempData["PhoneVarificationMissing"];
}
Here I am getting null value

Francis SusaimichaelRank #466 · 5.4K reputationPosted Jun 30, 2016, 7:12 AM EDT
Why don't you use "Session" instead of "TempData". Since Tempdata is:
TempData is used to pass data from current request to subsequent request (means redirecting from one page to another).
It’s life is very short and lies only till the target view is fully loaded.
http://www.dotnet-tricks.com/Tutorial/mvc/9KHW190712-ViewData-vs-ViewBag-vs-TempData-vs-Session.html
Karthik ElumalaiRank #544 · 4.5K reputationPosted Jun 30, 2016, 8:08 AM EDT
//Controller Code
public ActionResult Index()
{
List<string> Student = new List<string>();
Student.Add("Jignesh");
Student.Add("Tejas");
Student.Add("Rakesh");
TempData["Student"] = Student;
return View();
}
//page code
<ul>
<% foreach (var student in TempData["Student"] as List<string>)
{ %>
<li><%: student%>li>
<% } %>
ul>
Gopal Singh5 reputationPosted Jun 30, 2016, 8:50 PM EDT
Karthik Sachin
Rajeev PunhaniRank #551 · 4.4K reputationPosted Jun 30, 2016, 11:14 PM EDT
If the above solution is helpful then,accept the answer.
Francis SusaimichaelRank #466 · 5.4K reputationPosted Jun 30, 2016, 11:18 PM EDT
My concern is different.
Gopal Singh5 reputationPosted Jul 1, 2016, 5:47 AM EDT