IEnumerable<Addresses> AddressSet1=myServices.GetAddresses(LocationId1);
IEnumerable<Addresses> AddressSet2=myServices.GetAddresses(LocationId2);
我想合并以上两个AddressSets
I tried IEnumerable<Addresses> AllAddresses=AddressSet1.Concat(AddressSet2)
但在此之后,当我尝试通过我的剃刀视图访问 IEnumerable AllAddresses 中的项目时
@if(!myHelper.IsNullorEmpty(model.AllAddresses )
{
@Html.EditorFor(model => model.AllAddresses )
}
我收到错误 - 路径中存在非法字符。有什么建议可以确定此错误的原因吗?
如果我尝试在没有 Concat 的情况下运行我的页面,我可以看到页面上显示的 AddressSet1 /AddressSet2 中的记录。但是当我尝试将两者组合形成 I Enumerable AllAddresses 时,它会抛出错误,请帮助
下面粘贴的是我的编辑器模板
@model MyServiceRole.Models.Addresses
@{
ViewBag.Title = "All addresses Items";
}
<table>
<tr>
<td>
<span>Index</span>
</td>
<td>
</tr>
<tr>
<td>Address XID</td>
<td>
@Html.EditorFor(model => model.AddressID)
</td>
</tr>
<tr>
<td>Title</td>
<td>
@Html.EditorFor(model => model.Title)
</td>
</tr>
<tr>
<td>Description</td>
<td>
@Html.EditorFor(model => model.Description)
</td>
</tr>
<tr>
<td>Image URL</td>
<td>
@Html.EditorFor(model => model.Photo.URL)
</td>
</tr>
</table>
我测试了你的问题并遇到了同样的问题。
List<string> a = new List<string>{ "a" };
List<string> b = new List<string>{ "b" };
IEnumerable<string> concat = a.Concat<string>(b);
foreach(string s in concat) { } // this works
return View(concat);
In view:
@model IEnumerable<string>
@foreach(string s in Model) //This blows up
{
}
@Html.EditorFor(m => Model) //Also blows up
看起来你真的不能使用模板或枚举
System.Linq.Enumerable.ConcatIterator<T>
类Concat
在视图中创建。这似乎是一个错误。
无论如何添加.ToList()
解决你的问题。
return View(concat.ToList());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)