Exchange of data between actions

I am tasked with programming the website, and I am new to creating the website.

The website should show an overview of trips and allow navigation on one trip detail and these travel locations. Our database will return a list with trips and all its places:

class Trip { List<Place> places; }
List<Trip> trip = datalayer.GetTrips();

Thus, the request will already contain trips and all places. When we want to show one trip or place, there is no need to go to the database. Is it correct to store the list of routes in the cache, and then use the cache when displaying a trip or one of its places?

Code example:

//GET /Trips
public ActionResult Index()
{
    List<Trip> tripList;
    _dbLayer.GetTrips(out tripList);
    HttpContext.Current.Cache.["Trips-" + clientId] = tripList;
    return View(tripList);
}

//GET: /Trips/Details/5
public ActionResult Detail(int id)
{
    List<Trip> tripList = HttpContext.Current.Cache.["Trips-" + clientId];
    if(tripList != null)
    {
      Trip trip = tripList.SingleOrDefault(i => i.TechNr == id)
      return View(trip);
    }
    else
    {
       return View("NotFound");
    }
 }
+3
source share
2 answers

Linq to SQL datacontext, . , .

+2

( ), sql . , , , , . SQL Server, Scott Hansellman

0

Source: https://habr.com/ru/post/1733034/


All Articles