IEnumerable<Addresses> AddressSet1=myServices.GetAddresses(LocationId1);
IEnumerable<Addresses> AddressSet2=myServices.GetAddresses(LocationId2);
I want to combine the above two AddressSets
I tried IEnumerable<Addresses> AllAddresses=AddressSet1.Concat(AddressSet2)
But after this when I try to access items from IEnumerable AllAddresses by on my razor view
@if(!myHelper.IsNullorEmpty(model.AllAddresses )
{
@Html.EditorFor(model => model.AllAddresses )
}
and I am getting errors -- Illegal characters in path .Any suggestions to identify cause of this error ?
If I am trying to run my page with out the Concat I am able see the records in AddressSet1 /AddressSet2 displayed on the page .But when I try to combine the two to form I Enumerable AllAddresses ,it is throwing errors please help
pasted below is my Editor Template
@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>
If you want to use editor templates why are you writing
foreach
loops? You don't need this loop at all. Simply write the following and get rid of theforeach
:and then you will obviously have a corresponding editor template that ASP.NET MVC will automatically render for each element of the
AllAddresses
collection so that you don't need to write any foreach loops in your view (~/Views/Shared/EditorTemplates/Address.cshtml
):I tested your issue and ran into the same problem.
In view:
It looks like you honestly can't use templates with or enumerate over the
class that
Concat
creates within a View. This seems like a bug.Anyway adding
.ToList()
fixes your issue.