Hello everyone how to pass two or more than IEnumerables lists to view? Here is my action controller:
ServicesClient client = new ServicesClient();
client.ClientCredentials.UserName.UserName = "service_test";
client.ClientCredentials.UserName.Password = "..";
client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
ListCity[] city = client.GetCity();
ListStreet[] street = client.GetStreet(2);
return View(city);
And my View:
model IEnumerable<ListCity>
@using icerik.EmlakServices
@{
Layout = "~/Views/Shared/Test.cshtml";
}
<select>
@foreach(var item in Model)
{
<option>@Html.DisplayFor(x => item.CityName)</option>
}
</select>
You have to create a ViewModel in this case. So something like this:
Then in your controller:
Then in your view:
Then you can get the collections in your view like
Model.City, orModel.Street.For all but the very basic cases, you usually end up creating a ViewModel for almost all your views. So name them properly so you know what they are doing. I called it
MyViewModelin the example since I don’t know the context.Also, I would name the variables
CitiesandStreetssince they are collections, and not just single elements.