【发布时间】:2013-12-17 17:15:10
【问题描述】:
我目前有一个模型将狗变量传递到视图中:
public ActionResult Summary()
{
var dogs = repository.GetAllRecords().OrderByDescending(x => x.DateRecieved);
return View("Summary", dogs);
}
其中有一个名为 OutcomeID 的字段,它通过 ID 引用另一个数组:
var categories = new List<Category>();
try
{
this.Connect();
var cmd = new SqlCommand
{
CommandText = "dbo.GetSummaryOutcomes",
CommandType = CommandType.StoredProcedure,
Connection = this.cn
};
var result = cmd.ExecuteReader();
while (result.Read())
{
categories.Add(new Category
{
Name = result["Outcome"].ToString(),
Value = result["id"].ToString(),
InUse = bool.Parse(result["InUse"].ToString())
});
}
}
无论如何,我认为我可以将这些组合起来,而不是仅使用 OutcomeID,而是从类别列表中引用 Outcome 结果?
即我需要根据匹配dogs.OutcomeID 到result["id"] 来获得result["Outcome"]
对不起,如果这听起来像一个愚蠢的问题,在 PHP 中这对我来说不是问题,但我对 ASP.NET MVC 很陌生,我不知道从哪里开始
谢谢
【问题讨论】:
标签: c# asp.net asp.net-mvc