【发布时间】:2013-10-04 02:10:17
【问题描述】:
我想将查询 (JSON) 的结果从控制器传递到局部视图,这就是我创建强类型的原因,如下所示:
public class Suivi_Client
{
public string ClientID { get; set; }
public string Activite { get; set; }
public string ClientName { get; set; }
}
// list
public class Suivis
{
public List<Suivi_Client> List_Clients { set; get; }
}
然后是局部视图:
@model IEnumerable<Project.Models.Suivi_Client>
<html>
<body>
<table border=1>
<thead>
<tr>
<th>
ID
</th>
<th>
Name
</th>
<th>
Activite
</th>
</tr>
</thead>
@foreach(var item in Model){
foreach (var pop in item.List_Clients)
{
<tr>
<td >
@Html.DisplayFor(modelItem => pop.ClientID)
</td>
< <td >
@Html.DisplayFor(modelItem => pop.ClientName)
</td>
<td >
@Html.DisplayFor(modelItem => pop.Activite)
</td>
</tr>
}
}
</table>
</body>
</html>
这里是动作方法:
public ActionResult Partial_suivi(string clients)
{
IEnumerable<Suivis> PopModel;
var activit = (from x in frh.productivites
join y in frh.Clients on x.action equals y.ClientName
where x.action.Equals(clients)
select new { x.actionID,x.Activité,y.ClientName,y.Responsable,y.TempsCible,x.tempsmoy_ }).Distinct().ToArray();
PopModel = activit;
return PartialView(PopModel);
}
但我有这个错误:无法将类型“AnonymousType #1 []”转换为“Project.Models.Suivis”
我该如何解决这个错误?
【问题讨论】:
标签: json asp.net-mvc-4 razor partial-views anonymous-types