The Class that is using the container is throwing an error on AmountList and PGRow that says AmountList is inaccessible due to its protection level
The Code
public virtual ActionResult getAjaxPGs(string SP = null, string PG = null)
{
if (SP != null)
{
Container container = new Container();
var PGList = from x in db.PG_mapping
where x.PG_SUB_PROGRAM == SP
select x;
container.PARow = PGList.Select(x => new { x.PG }).Distinct().ToArray();
container.AmountList = from x in db.Spend_Web
where x.PG == PG
group x by new { x.ACCOUNTING_PERIOD, x.PG, x.Amount } into pggroup
select new { accounting_period = pggroup.Key.ACCOUNTING_PERIOD, amount = pggroup.Sum(x => x.Amount) };
return Json(container, JsonRequestBehavior.AllowGet);
}
return View();
}
public class Container
{
Array PARow;
Array AmountList;
}
I tried making the class public, do I have to do something else to make the class accessible to getAjaxPGs??
By default, class members are
private– the are only accessible to the class itself.You need to declare them as public if you want to access them from outside the class (or
internalif the code that requires access only ever exists in the same assembly).Note: the above (public access to fields) is considered bad practice – you should be using properties for this.