有没有办法在 ASP MVC3@Html.DisplayFor()
控件中使用条件?下面是我尝试的语法。虽然看起来partner.TradingPartners
可以使用 .Where<>
,但根据 Visual Studio 我做错了!
这是我使用的语法
@foreach (var item in Model.Agent.SymNumberToAgentId)
{
var gogo = ViewBag.Periscope + item.AgentId.Trim();
<tr>
<td>
@Html.DisplayFor(modelItem => item.DisplayAgentId)
</td>
<td>
@Html.DisplayFor(modelItem => item.CompanyCode)
</td>
<td>
@foreach (var partner in Model.AgentIdDetails)
{
@Html.DisplayFor(modelItem => partner.TradingPartners.Where(item => item.AgentId == partner.AgentId))
}
</td>
<td>
@Html.ActionLink("Remove", "Delete", "SymetraNumberToAgentId", new { id = item.SymetraNumber, aid=item.AgentId}, null)
</td>
<td>
<a href=@gogo target="_blank">View in Periscope</a>
</td>
</tr>
}
这是错误消息
CS1928: 'System.Collections.Generic.IList<string>' does not contain a definition for 'Where' and the best extension method overload 'System.Linq.Enumerable.Where<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)' has some invalid arguments