I have employee class
public class Employee
{
public string Name { get; set; }
public string EmpID { get; set; }
public string Designation { get; set; }
}
I want the same using TempData
on View....
if I use @TempData["Employee"]
I am getting modal.employee which is fair enough..
please suggest
To set data in TempData
-
TempData["Employee"] = new Employee() {Designation = "Manager"};
To retrieve it in view -
@{
var emp = TempData["Employee"] as Employee;
}
Use emp
variable in later part of the view.
<div>@emp.Designation</div>
IMPORTANT Any object in TempData
will be removed once it is read (or)retrieved. To keep it in TempData
for further usage, use Tempdata.Keep()
TempData.Keep("Employee");
Alternatively you can use ViewBag
to send data from Controller to View.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With