Sunny Bhor

Sunny Bhor

  • NA
  • 31
  • 602

Pass Dynamic data to View

Nov 13 2018 1:12 AM
I have mvc web application in which I passed the dynamic data to view which is coming from db context.
 
Which will be the better approach either use expando object or viewbag/viewdata ?

Current code : 

Viewbag.List1 = context.getlist1();
  

Viewbag.List2 = context.getlist2();

Viewbag.List3 = context.getlist3();

Viewbag.List4 = context.getlist4();
 
ViewBag.string1 = string1;

ViewBag.string2 = string 2; 
 
 I am trying to change code like 

dynamic tempModel = new ExpandoObject();

tempModel .List1 = context.getlist1();

tempModel .List2 = context.getlist2();

tempModel .List3 = context.getlist3();

tempModel .List4 = context.getlist4();
 
tempModel .string1 = string1;

tempModel .string2 = string 2;

And pass tempModel to View.




 

Answers (6)