【发布时间】:2014-07-06 00:23:12
【问题描述】:
谁能帮我解决我在课堂上遇到的问题?
我有一个地址类:
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; }
}
我有一个路由类:
public class Route
{
public Address from { get; set; }
public Address to { get; set; }
}
在我的控制器中,我设置了一些类似这样的虚拟信息:
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);
}
但是当我运行项目时,它会落在 myroute.from.addressDescription = from;表示对象引用未设置为对象实例的行。
我看不出我做错了什么。有人可以帮忙吗?
谢谢
特雷夫
【问题讨论】:
-
正确答案如下,但您应该考虑将路由重命名为其他名称。 Route 在 MVC 中意味着什么。
标签: c# .net asp.net-mvc