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