public class CityDto : IEnumerable<CityDto>
{
public IEnumerator<CityDto> AllCities { get; set; }
private List<CityDto> _CityDto;
public IEnumerator<CityDto> GetEnumerator()
{
return _CityDto.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _CityDto.GetEnumerator();
}
#region Constructors
/// <summary>
/// Initializes a new instance of the CityMasterdto class.
/// </summary>
public CityDto()
{
}
/// <summary>
/// Initializes a new instance of the CityMasterdto class.
/// </summary>
public CityDto(string city_name, long state_id, bool active)
{
this.City_name = city_name;
this.State_id = state_id;
this.Active = active;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the state name value.
/// </summary>
public string State_name { get; set; }
/// <summary>
/// Gets or sets the City_id value.
/// </summary>
public long City_id { get; set; }
/// <summary>
/// Gets or sets the City_name value.
/// </summary>
[Display(Name="City Name")]
[Required]
public string City_name { get; set; }
/// <summary>
/// Gets or sets the State_id value.
/// </summary>
public long State_id { get; set; }
public bool Active { get; set; }
#endregion
}
И это мой код контроллера:не в состоянии получить IEnumerable коллекции модели представления, ток Перечислитель всегда нуль
public ActionResult index()
{
return View(GetCities(obj.Details()).AsEnumerable());
}
private IEnumerable<CityDto> GetCities(DataSet ds)
{
foreach (DataRow row in ds.Tables[0].Rows)
{
yield return new CityDto
{
City_id = Convert.ToInt32(row["city_id"]),
City_name = Convert.ToString(row["city_name"]),
State_name = Convert.ToString(row["state_name"]),
State_id = Convert.ToInt32(row["state_id"])
};
}
}
Там не все ошибки сборки, но когда я запускаю код, я получаю ошибка:
The model item passed into the dictionary is of type 'MvcApplication.Areas.Admin.Controllers.CityController+d__1', but this dictionary requires a model item of type 'MvcApplication.Areas.Admin.Models.CityDto'.
, но я не понимаю, что это значит ....
System.Collections.Generic.IEnumerator<MvcApplication.Areas.Admin.Models.CityDto>.Current == null
и
System.Collections.IEnumerator.Current == null
также
ds == null
, но просмотр результатов показывает ожидаемые данные
Ваш '_CityDto' никогда не инициализируется. –
где я должен его инициализировать? –
Не знаю. Что вы хотите с этим делать? –