Accessing value from dynamic object

33 Views Asked by At
public ActionResult GetBindata(int index) {
  Pallet[] ActivePallets = ViewBag.ActivePalletArr;
  var bindata =
      ApplicationConfig.configdata.GetValueData(SettingTypeEnum.BinCode)
          .GroupBy(x => new {x.description})
          .Select(
              x => new {
                  Zone = x.Key.description,
                  Location =
                      x.Select(
                           s => new {PalletItem = ActivePallets.FirstOrDefault(
                                         a => a.GetLocation() == s.key),
                                     BIN = s.key, LOCATION = s.value})
                          .Select(s => new {
                                      PalletItem = s.PalletItem,
                                      Aging = (DateTime.Now -
                                               (s.PalletItem?
                                                    .CreatedOn ?? DateTime.Now))
                                                  .Days,
                                      BIN = s.BIN, LOCATION = s.LOCATION})})
          .OrderByDescending(x => x.Zone)
          .ToArray();
  var zoneSel = bindata[index];
  try {
    return PartialView("~/Views/WHManager/_BindataPartialView.cshtml", zoneSel);
  } catch (Exception e) {
    System.Diagnostics.Debug.WriteLine(e);
    return View();
  }
}

This is what I currently have for a C# application. I am passing an index of bindata to one of partial view .cshtml named _BindataPartialView.cshtml.

My problem comes along with accessing values from passed data. Since I am using dynamic for my model, it is very hard to read or write the HTML file.

What can I do to make this easier to access data that is passed on from controller?

here is my partial view .cshtml:

@using SGSWMS.Models;
@model dynamic

@{
    var areadata = Model;
    //System.Diagnostics.Debug.WriteLine();
}

<!-- Render zone details -->

<b>@Model.GetType().GetProperty("Zone").GetValue(Model, null)</b>

<script>


</script>
0

There are 0 best solutions below