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
Gopal SinghPosted Jul 1, 2016, 9:47 AM
Francis SusaimichaelPosted Jul 1, 2016, 3:18 AM
My concern is different.
Rajeev PunhaniPosted Jul 1, 2016, 3:14 AM
If the above solution is helpful then,accept the answer.
Gopal SinghPosted Jul 1, 2016, 12:50 AM
Karthik Sachin
Karthik ElumalaiPosted Jun 30, 2016, 12:08 PM
//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>
Francis SusaimichaelPosted Jun 30, 2016, 11:12 AM
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