0

Based on this tutorial i am trying to make my own project, but i have a problem

Visual Studio 2010 .net 4.0

SQL 2008 R2

My Database Table

Iller

ID int
ILKod varchar(5)
IlAciklama nchar(20)

My Model

 namespace BilgiBankasi.Models
{
    public class Iller
    {
        public int ID { get; set; }

        public int ILKod { get; set; }

        public string IlAciklama { get; set; }
    }

    public class BilgiBankasiEntities : DbContext
    {
        public DbSet<Iller> Iller { get; set; }
    }

}

My Controller

namespace BilgiBankasi.Controllers
{
    public class IlTestController : Controller
    {
        //
        // GET: /IlTest/

        BilgiBankasiEntities _db = new BilgiBankasiEntities();

        public ActionResult Index()
        {
            var model = _db.Iller.ToList();
            return View(model);
        }

        public ActionResult Create()
        {
            return View();
        }

    }
}

My View

@model IEnumerable<BilgiBankasi.Models.Iller>

In this situation i get this error

The model item passed into the dictionary is of type 'System.Collections.Generic.List1[BilgiBankasi.Iller]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[BilgiBankasi.Models.Iller]'.

But when i use

This comes from Model.edmx

@model IEnumerable<BilgiBankasi.Iller>

works great.

What am i missing ? Am i doing something wrong or is there a bug? The Scaffolding from model doesn't work either. I create all views myself.

5
  • try var model = _db.Iller.ToList().AsEnumerable(); Commented Oct 30, 2011 at 12:30
  • i tried that too the error is The model item passed into the dictionary is of type 'System.Data.Objects.ObjectSet1[BilgiBankasi.Iller]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[BilgiBankasi.Models.Iller]'. Commented Oct 30, 2011 at 12:31
  • 1
    You are using DbContext API, but it seems you have a .edmx (ObjectContext API) file too, can you please more explain? Clean and ReBuild the entire solution, ma be helpful too. Commented Oct 30, 2011 at 12:32
  • 1
    The fact that it is reporting BilgiBankasi.Iller, not the one in Models, tells me that it isn't using your model type. Presumably there is a BilgiBankasi.Iller from the edmx/dbml. Commented Oct 30, 2011 at 12:33
  • Agree with Marc. There must be a BilgiBankasi.Iller hanging around somewhere. Commented Oct 30, 2011 at 12:35

1 Answer 1

1

Found the problem. connection string was System.Data.Entity and i change to System.Data.Sqlclient

Thanks everyone for spending time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.