I been stuck in a situation and I tried finding the solution for it on net but was not successful. I am new to MVC with Entity Framework, and it is throwing the exception when i try to run the application:
The model item passed into the dictionary is of type
'System.Data.Entity.Infrastructure.DbQuery1[<>f__AnonymousType1
2[UnRelatedEntity.Models.t_AbortReason,UnRelatedEntity.Models.t_Activity]]',
but this dictionary requires a model item of type
'UnRelatedEntity.Models.MobilePhoneXchangeEntities1'
I am using an Entity as a model which fetches Data from two tables seperately which do not have relation among them.
Controller:
public ActionResult Index()
{
MobilePhoneXchangeEntities1 ent = new MobilePhoneXchangeEntities1();
var result = from foo in ent.t_AbortReason
from bar in ent.t_Activity
where foo.AbortReasonCategoryId != null && bar.ActivityId != null
select new { Foo = foo, Bar = bar };
return View(result);
}
View
@model UnRelatedEntity.Models.MobilePhoneXchangeEntities1
In the view I am just writing the above line i mean i am just inheriting the Model, nothing else but still I am confused about how to type cast model w.r.t model, but I am helpless.
Can anyone please provide me help on this, but please keep in mind i am using two unrelated tables in my model.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…