سلام دوستان گرامي كد زير چرا خطا ميده:
public class ItemsOfQuestions { public string item_title { get; set; } public Byte item_type { get; set; } public string item_image { get; set; } public Int16 item_grade { get; set;} } public class Questins_With_Items { public string question_title { get; set; } public List<ItemsOfQuestions> list_items { get; set; } } بصورت زیر استفاده میکنم : List<ItemsOfQuestions> itemlist = new List<ItemsOfQuestions>(); Questins_With_Items qwi = new Questins_With_Items(); for (int i = 0; i < 5; i++) { ItemsOfQuestions ioq = new ItemsOfQuestions(); ioq.item_title = "item"+i.ToString(); ioq.item_type = 0; ioq.item_image = ""; ioq.item_grade = (Int16)i; itemlist.Add(ioq); } qwi.question_title = "سوال اول"; qwi.list_items.Add(itemlist);
خطا در خطر آخره
به شکل زیر استفاده کنید برای کلاس Questins_With_Items باید سازنده بزاید
public class ItemsOfQuestions { public string item_title { get; set; } public Byte item_type { get; set; } public string item_image { get; set; } public Int16 item_grade { get; set;} } public class Questins_With_Items { public string question_title { get; set; } public List<ItemsOfQuestions> list_items { get; set; } public Questins_With_Items() { list_items =new List<ItemsOfQuestions>(); } } List<ItemsOfQuestions> itemlist = new List<ItemsOfQuestions>(); Questins_With_Items qwi = new Questins_With_Items(); for (int i = 0; i < 5; i++) { ItemsOfQuestions ioq = new ItemsOfQuestions(); ioq.item_title = "item"+i.ToString(); ioq.item_type = 0; ioq.item_image = ""; ioq.item_grade = (Int16)i; itemlist.Add(ioq); } qwi.question_title = "سوال اول"; qwi.list_items.Add(itemlist);
ممنون آقای مدائنی چه جوری در ویو ازش اسفاده کنیم در حلقه foreach خطا میده میگه اطلاعات مدل باید IEnumerable باشه
مدل صفحه را چگونه تعریف کردید
کدش را قرار دهید
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)