[HttpGet] public ActionResult Create() { return View(); } [HttpPost] public ActionResult Create(FormCollection formCollection) { Employee employee = new Employee(); // Retrieve form data using form collection employee.Name = formCollection["Name"]; employee.Gender = formCollection["Gender"]; employee.City = formCollection["City"]; employee.DateOfBirth = Convert.ToDateTime(formCollection["DateOfBirth"]); businesslayer.AddEmmployee(employee); TempData["Employees"] = employee; return RedirectToAction("Testtempdata"); } public ActionResult Testtempdata() { Employee employee = TempData["Employees"] as Employee; return View(employee); }
Index View: { ViewBag.Title = "Index"; } <h2>Index</h2> @Html.ActionLink("Testtempdata","Testtempdata")
@model @{ ViewBag.Title = "Testtempdata"; } <h2>Testtempdata</h2> @{Html.BeginForm("Testtempdata", "Testtempdata", FormMethod.Post);} <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td class="inner_databg"> </td> </tr> <tr> </tr> </table>
@model Employee @{ ViewBag.Title = "Testtempdata"; } //then you can access employee values like this <p>@Model.EmployeeProperty1</p>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)