currently i am using ViewData and Viewbag for storing data and tempdata for redirection all are working fine.
i just want to know is there any optimize way to store data or controls values during postback in MVC ?
this is my controller method , i am passing two model classes from controller to view using dynamic object.
[HttpGet]
public ActionResult Index(int? page)
{
IList<Customer> _CustomerList = new List<Customer>();
IList<LCOddl> LCODDL= new List<LCOddl>();
// some logic to bind both classed with database ..
dynamic DashboardClassed = new ExpandoObject();
DashboardClassed.LCODDL = LCODDL;
DashboardClassed.CUSTOMER = _CustomerList.ToPagedList(page ?? 1, 30);
return View(DashboardClassed);
}
here is my razor view which use dynamic object :
@using PagedList;
@using PagedList.Mvc;
@model dynamic
@{
Layout = null;
}
@using (Html.BeginForm("SearchMethod", "Dashboard", FormMethod.Post))
{
@foreach (Models.LCOddl item in Model.LCODDL)
{
// Render HTML
}
@foreach (Models.Customer item in Model._CustomerList )
{
// render html
}
<div class="form-group"><button type="submit" class="btn btn-success">Go</button></div>
}
after button click from my razor view SearchMethod from Dashboard Controller will called .
Now here i want two things :
- Don't want to bind customer class again with database - for that i am using tempdata .
- i have to maintain paging using PagedList.
again my question is same should i use tempdata for storing data or is there any other optimize way to do the same.