我的控制器有问题。我的表中的数据未显示在我的强类型视图中。但是当我return View(CanaClie0012.toList())
;我可以完美地看到我的数据。我没有收到任何错误。有人可以告诉我我做错了什么。
我的表模型:
public partial class CanaClie0012
{
public string Client00130012 { get; set; }
public string F1Pais00200012 { get; set; }
public string F1Cana02530012 { get; set; }
public string Direcc0012 { get; set; }
public Nullable<System.DateTime> TmStmp0012 { get; set; }
}
public partial class Clientes0013
{
public string Client0013 { get; set; }
public string Nombre0013 { get; set; }
public string F1Pais00200013 { get; set; }
}
我的自定义模型组合这两个表是:
public class ClientModel
{
public CanaClie0012 CanaClie0012 { get; set; }
public Clientes0013 Clientes0013 { get; set; }
}
我的控制器:
public ViewResult Index()
{
List<ClientModel> lm = new List<ClientModel>();
ClientModel vm = new ClientModel();
lm.Add(vm);
return View(lm);
}
我的观点:
@model IEnumerable<ContactManager.Models.ClientModel>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
Client00130012
</th>
<th>
F1Pais00200012
</th>
<th>
F1Cana02530012
</th>
<th>
Direcc0012
</th>
<th>
TmStmp0012
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.CanaClie0012.Client00130012)
</td>
<td>
@Html.DisplayFor(modelItem => item.CanaClie0012.F1Pais00200012)
</td>
<td>
@Html.DisplayFor(modelItem => item.CanaClie0012.F1Cana02530012)
</td>
<td>
@Html.DisplayFor(modelItem => item.CanaClie0012.Direcc0012)
</td>
<td>
@Html.DisplayFor(modelItem => item.CanaClie0012.TmStmp0012)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>