با درود
من دو مدل تعریف کردم به شکل زیر
و سپس یک ViewModel برای این دو مدل و بکارگیری آن در یک View
public class Estates
{
public int id { set; get; }
public string City { set; get; }
}
public class Options
{
public int id { set; get; }
public string Address { set; get; }
}
و گرفتن اطلاعات از بانک با کوئری Linq
public class MyViewModels
{
public IEnumerable<Estates> Estate { get; set; }
public IEnumerable<Options> Option { get; set; }
}
و View متناظر با این اکشن که 2 مدل در آن نمایش داده میشود
public ActionResult Index()
{
EstateContext db = new EstateContext();
var data = (from s in db.Estate
from c in db.Option
select s).ToList();
return View(data);
}
اما با اجرای برنامه خطای زیر داده میشه
@model Amlak.ViewModels.MyViewModel
@foreach (var item in Model.Estate)
{
@item.City
}
@foreach (var item in Model.Option)
{
@item.Address
}
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Amlak.Models.Estates]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Amlak.ViewModels.MyViewModels]'.
دو روزه گرفتار این خطا شدم
ممنون میشم راهنمایی کنید