Can anyone help me get around my problem with my class please?
I have an Address class:
public class Address
{
public string addressDescription { get; set; }
public string addressNumber { get; set; }
public string adddressLine1 { get; set; }
public string adddressLine2 { get; set; }
public string adddressLine3 { get; set; }
public string addressPostCode { get; set; }
public double addressLatitude { get; set; }
public double addressLongitude { get; set; }
}
And I have a Route Class:
public class Route
{
public Address from { get; set; }
public Address to { get; set; }
}
And in my controller i have setup some dummy information like this:
public ActionResult FareCalculator(string from , string to)
{
var myroute = new Route();
myroute.from.addressDescription = from;
myroute.from.addressLatitude = 51.481581;
myroute.from.addressLongitude = -3.179090;
myroute.to.addressDescription = to;
myroute.to.addressLatitude = 51.507335;
myroute.to.addressLongitude = -0.127683;
return View(myroute);
}
but when i run the project it falls over on the myroute.from.addressDescription = from; line saying Object reference not set to an instance of an object.
I cannot see what I am doing wrong. Can anyone help please?
Thanks
Trev