0

Ive really searched all over the web and im just stack on this problem.. pls help :( (new with MVC) when im trying to run a specific page , im getting the message:

System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Category_B85D1A3F838C0192719C683B1095328267C570F7A660F0D', but this dictionary requires a model item of type 'Leeoriyas.Models.Category'.

my controller "storecontroller" (the relevent part)

 using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Leeoriyas.Models;

    namespace Leeoriyas.Controllers

public class StoreController : Controller
    {
        LeeoriyasFPEntities storeDB = new LeeoriyasFPEntities();
        // GET: Store


     public ActionResult Index()
            {
                return View(storeDB.Category.ToList());
            }
 public ActionResult Browse(string Category)
        {
            var categoryModel = storeDB.Category.Include("ArtS").Single(c => c.Name == Category);
                return View(categoryModel);
        }

my view (browse)

@model Leeoriyas.Models.Category


@{
    ViewBag.Title = "Browse";
}

<h2>Browsing category: @Model.Name</h2>

<ul>
    @foreach (var product in Model.ArtS)
    {
        <li>
            @product.Title
        </li>
    }
</ul>

thanks!! :(

1 Answers1

0

You are not sending what is expected to your view. You specify a type of Leeoriyas.Models.Category, so ensure that you are passing an object of that kind. You should pass something like this:

 public ActionResult Browse(string category)
        {
            Leeoriyas.Models.Category categoryModel = storeDB.Category.Include("ArtS").Single(c => c.Name == category);
                return View(categoryModel);
        }

Ensure that the return of this line storeDB.Category.Include("ArtS").Single(c => c.Name == category); is of type Category

NicoRiff
  • 4,803
  • 3
  • 25
  • 54