I can't seem to get my class to instantiate. When I run my web application. I'm trying to pass the results of my class into some google charts but can't seem to get the class to instantiate. Any help/links/code would be greatly appreciated.
This is where I seem to be stuck:
DashboardController.cs
using System.Web.Mvc;
namespace AudAPIApp.Controllers
{
[Authorize]
public class DashboardController : Controller
{
public ActionResult Index()
{
GoogleAPI googleReport = new GoogleAPI();
return View(googleReport);
//New to MVC not sure if this is how to instantiate my class?
}
}
}
I've placed code blocks in my class and my application doesn't run through it.
GoogleApi.cs
namespace AudAPIApp
{
public class GoogleAPI
{
public static GetReportsResponse googleRpt;
static void Main(string[] args)
{
try
{
//code that gets all the data. This all works in a console app I made. My challenge is making it work in MVC.
var response = batchRequest.Execute();
googleRpt = response;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
Index.cshtml
<script>
var googleData = [];
@{
//this is where I get error: "Object reference not set to an instance of an object."
foreach(var x in GoogleAPI.googleRpt.Reports.First().Data.Rows)
{
@:googleData.push([@x.Dimensions, @x.Metrics])
}
}
</script>
I know that this shouldn't work either because it is using an un instantiated object.