littlegeek
littlegeek

Reputation:

MVC Model issue can you diagnose what this is saying?

This is part of the first build repoistory that sits on Microsoft MVC.

First call from the controller down for model.

 public ActionResult Index()
        {
            var prog = yRepository.FindUpComingProgrammes();
            return View(prog);
        }

ASP ERROR:

Server Error in '/' Application.
--------------------------------------------------------------------------------

The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[Code.Models.Prog]' but this dictionary requires a model item of type 'Code.Models.Prog'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[Code.Models.Prog]' but this dictionary requires a model item of type 'Code.Models.Prog'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[InvalidOperationException: The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[Code.Models.Prog]' but this dictionary requires a model item of type 'Code.Models.Prog'.]
   System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) +116376
   System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +369
   System.Web.Mvc.ViewPage`1.SetViewData(ViewDataDictionary viewData) +59
   System.Web.Mvc.WebFormView.RenderViewPage(ViewContext context, ViewPage page) +70
   System.Web.Mvc.WebFormView.Render(ViewContext viewContext, TextWriter writer) +92
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +278
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +10
   System.Web.Mvc.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e() +20
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +251
   System.Web.Mvc.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +178
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +399
   System.Web.Mvc.Controller.ExecuteCore() +126
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +27
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +151
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Upvotes: 1

Views: 2341

Answers (1)

RSolberg
RSolberg

Reputation: 26972

It sounds like you are using a strongly typed view and the object being passed to the view is not the same that type that the view is bound to...

Upvotes: 3

Related Questions