Hi i need to show a list of data using viewbag.but i am not able to do it.
Please Help me..
I tried this thing:
ICollection list = ne
i had the same problem and i search and search .. but got no result.
so i put my brain in over drive. and i came up with the below solution.
try this in the View Page
at the head of the page add this code
@{
var Lst = ViewBag.data as IEnumerable<MyProject.Models.Person>;
}
to display the particular attribute use the below code
@Lst.FirstOrDefault().FirstName
in your case use below code.
<td>@Lst.FirstOrDefault().FirstName </td>
Hope this helps...
This is what i did and It worked...
C#
ViewBag.DisplaylList = listData;
javascript
var dispalyList= @Html.Raw(Json.Encode(this.ViewBag.DisplaylList));
for(var i=0;i<dispalyList.length; i++){
var row = dispalyList[i];
..............
..............
}
//controller You can use this way
public ActionResult Index()
{
List<Fund> fundList = db.Funds.ToList();
ViewBag.Funds = fundList;
return View();
}
<--View ; You can use this way html-->
@foreach (var item in (List<Fund>)ViewBag.Funds)
{
<p>@item.firtname</p>
}