Temp data example(Index):-
if (RouteId != null)
{
HttpContext.Session.SetString("RouteId", RouteId);
}
else
{
RouteId = HttpContext.Session.GetString("RouteId");
if (RouteId == null)
{
//return to the View and display an error message
TempData["message"] = "Please select a route.";
return RedirectToAction("Index", "BusRoute");
}
}
var routeStopViewModel = from routeStop in _context.RouteStop.Include(rs => rs.BusRouteCode)
select new RouteStopModel
{
BusRouteCode = routeStop.BusRouteCode
};
var routeStopsContext = _context.RouteStop
.Include(rs => rs.BusStopNumberNavigation)
.Where(predicate: rs =>rs.BusRouteCode==RouteId)
.OrderBy(keySelector: rs => rs.OffsetMinutes).ToListAsync();
Edit in the Controller:-
public async Task<IActionResult> Edit(int id,
[Bind("RouteStopId,BusRouteCode,BusStopNumber,OffsetMinutes")]
RouteStop
routeStop)
{
if (id != routeStop.RouteStopId)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
_context.Update(routeStop);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!RouteStopExists(routeStop.RouteStopId))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
ViewData["BusRouteCode"] = new SelectList(_context.BusRoute,
"BusRouteCode", "BusRouteCode", routeStop.BusRouteCode);
ViewData["BusStopNumber"] = new SelectList(_context.BusStop,
"BusStopNumber", "BusStopNumber", routeStop.BusStopNumber);
return View(routeStop);
CLubs (Edit):-
if (id != club.ClubId)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
_context.Update(club);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ClubExists(club.ClubId))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
ViewData["StyleCode"] = new SelectList(_context.Style,
"StyleCode",
"StyleCode", club.StyleCode);
return View(club);
}
@TempData["Name"]
and then I persist the data through keep method. @{ TempData.Keep("Name"); } – Vinay Jain Sep 19 '16 at 12:51