In my application, to load some data to the view (combo boxes) I have been using TempData
. I want to know if it is okay to use TempData
for that purpose?
My current code is here; first I called data to a list in controller:
List<Request_Types> RequestTyleList = db.Request_Types.Where(r => r.Status == true).ToList();
List<SelectListItem> ReqTypeDropDown = RequestTyleList.Select(r => new SelectListItem { Text = r.Request_Type, Value = r.Id.ToString() }).ToList();
Then I am assigning this data to TempData
:
TempData["RequestTyleList"] = ReqTypeDropDown;
In the view I called that temp data and assigning to the combo box
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
List<SelectListItem> ReqType = (List<SelectListItem>)TempData.Peek("RequestTyleList");
}
-----------------
<div class="form-group row">
@Html.LabelFor(model => model.ReqType, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-sm-8">
@Html.DropDownListFor(model => model.ReqType, ReqTypes, "Select Request Type", new { @class = "js-dropdown" })
@Html.ValidationMessageFor(model => model.ReqType, "", new { @class = "text-danger" })
</div>
</div>
If I want to access those same data in Edit, I again create a list and putting data to the list and transfer to TempData
and again call the same data from the view. Still I have 5 to 8 items of data on the list, I want to know when there are 100 items of data in TempData
, will my system get slow? Are there any potential performance issues?
While surfing this on the internet, I got that same will do in the Sessions
, but I don't know will it be suitable for this? Or else is there any good way to do this without dropping any performance of the system, like in one controller if I call and stores data, I can access those data from any view.