Finished 'TempData in ASP.NET MVC'

master
jason.zhu 2021-06-15 22:21:54 +10:00
parent 7433bb0d13
commit f826210b5f
1 changed files with 35 additions and 31 deletions

View File

@ -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()
TempData["Name"] = "Pranaya";
TempData["Age"] = 30;
return View();
}
public ActionResult Method2()
{
EmployeeId = 101,
Name = "Dillip",
Gender = "Male",
Department = "IT",
Salary = 10000,
AddressId = 1001
};
//Employee Address
Address address = new Address()
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()
{
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);
string Name;
int Age;
if (TempData.ContainsKey("Name"))
Name = TempData["Name"].ToString();
if (TempData.ContainsKey("Age"))
Age = int.Parse(TempData["Age"].ToString());
return View();
}
}
}