I'm working on ASP.NET MVC project with Entity Framework, the problem is I want to return data from Entity
to a viewbag
but this data structured by anonymous method (means I create manually the properties and their values that will returned to the viewbag), and the Viewbag
will returned to a view, and I want to use these values saved in the Viewbag
.
That what I try,
Controller :
public ActionResult SHOW()
{
var x = XController.xx();
ViewBag.DATA = x;
return View();
}
xx function :
public static dynamic xx()
{
var R = (from U in x_DB_Context.Con.UFs from P in x_Context.Con.FRMTRs select new { CODE = U.CD_UF, INTTL = U.NM_UF, FL = U.FL_UF, ANN = U.ANN_UF, STT = U.STT_UF, SMSTR = U.SMSTR_UF, COEF = U.COEF_UF, NBCTR = U.NB_CTR_UF, FRMTR = P.NM_FRMTR + " " + P.PRN_FRMTR }).ToList();
return R;
}
View :
@foreach (var item in ViewBag.DATA)
{
<tr>
<td>@item.CODE</td>
<td>@item.INTTL</td>
<td>@item.FL</td>
<td>@item.ANN</td>
<td>@item.SMSTR</td>
<td>@item.COEF</td>
<td>@item.NB_CTR</td>
<td>@item.FRMTR</td>
<td>@item.STT</td>
</tr>
}
When I try to access to this view
I saw error page with a big header message contains ('object' does not contain a definition for 'CODE')
Please any help, and a lot of thanks.