Search code examples
c#asp.net-coremodel-view-controllerviewbag

Can't get the data in viewbag


From a View, I am trying to access the data assigned to Viewbag in Controller. Here is what I tried so far:

The View:

@model SPES_PPS.Models.Benificiary

<h3>My partial view</h3>

<table>

@foreach (var item in ViewBag.bendetails)
{
    <tr>
        <td>Beni ID</td>
        <td>@item.benID</td>
    </tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
}


</table>

The Controller

   // GET: Benificiary/Details/
    public ActionResult Details(int id)
    {       
   Benificiary benificiary = db.Benificiaries.Find(id);
                if (benificiary == null)
                {
  return HttpNotFound();
                }
   ViewBag.bendetails = benificiary;
                return PartialView("Partial_Details", benificiary);

        }
    }

But it is not working, how can I get the data in Viewbag?


Solution

  • you can directly access data from model like @Model.itemName