Finished 'TempData in ASP.NET MVC'
parent
7433bb0d13
commit
f826210b5f
|
@ -11,38 +11,42 @@ namespace FirstMVCDemo.Controllers
|
|||
{
|
||||
public class EmployeeController : Controller
|
||||
{
|
||||
// GET: Employee
|
||||
public ActionResult Details()
|
||||
public ActionResult Method1()
|
||||
{
|
||||
//Employee Basic Details
|
||||
Employee employee = new Employee()
|
||||
{
|
||||
EmployeeId = 101,
|
||||
Name = "Dillip",
|
||||
Gender = "Male",
|
||||
Department = "IT",
|
||||
Salary = 10000,
|
||||
AddressId = 1001
|
||||
};
|
||||
//Employee Address
|
||||
Address address = new Address()
|
||||
{
|
||||
AddressId = 1001,
|
||||
City = "Bhubaneswar",
|
||||
State = "Odisha",
|
||||
Country = "India",
|
||||
Pin = "755019"
|
||||
};
|
||||
//Creating the View model
|
||||
EmployeeDetailsViewModel employeeDetailsViewModel = new EmployeeDetailsViewModel()
|
||||
{
|
||||
Employee = employee,
|
||||
Address = address,
|
||||
PageTitle = "Employee Details Page",
|
||||
PageHeader = "Employee Details",
|
||||
};
|
||||
//Pass the employeeDetailsViewModel to the view
|
||||
return View(employeeDetailsViewModel);
|
||||
TempData["Name"] = "Pranaya";
|
||||
TempData["Age"] = 30;
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Method2()
|
||||
{
|
||||
string Name;
|
||||
int Age;
|
||||
|
||||
if (TempData.ContainsKey("Name"))
|
||||
Name = TempData["Name"].ToString();
|
||||
|
||||
if (TempData.ContainsKey("Age"))
|
||||
Age = int.Parse(TempData["Age"].ToString());
|
||||
|
||||
TempData.Keep();
|
||||
|
||||
// do somethign with userName or userAge Ahere
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Method3()
|
||||
{
|
||||
string Name;
|
||||
int Age;
|
||||
|
||||
if (TempData.ContainsKey("Name"))
|
||||
Name = TempData["Name"].ToString();
|
||||
|
||||
if (TempData.ContainsKey("Age"))
|
||||
Age = int.Parse(TempData["Age"].ToString());
|
||||
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue