c# - How to fix The model item passed into the dictionary is of type error? -


i trying run first asp.net mvc application. created cotroller , view. data taken database. however, when project can run when try navigate customer page following error.

the model item passed dictionary of type 'system.collections.generic.list`1[mvcapplication3.models.customer]', dictionary requires model item of type 'mvcapplication3.models.customer'.

i bit confused here, error says has requesting model type.

stack trace

stack trace:

[invalidoperationexception: model item passed dictionary of type 'system.collections.generic.list1[mvcapplication3.models.customer]', dictionary requires model item of type 'mvcapplication3.models.customer'.]
system.web.mvc.viewdatadictionary
1.setmodel(object value) +585211
system.web.mvc.viewdatadictionary..ctor(viewdatadictionary dictionary) +371 system.web.mvc.viewpage1.setviewdata(viewdatadictionary viewdata) +48 system.web.mvc.webformview.renderviewpage(viewcontext context, viewpage page) +73
system.web.mvc.webformview.renderview(viewcontext viewcontext, textwriter writer, object instance) +38
system.web.mvc.buildmanagercompiledview.render(viewcontext viewcontext, textwriter writer) +115
system.web.mvc.viewresultbase.executeresult(controllercontext context) +295 system.web.mvc.controlleractioninvoker.invokeactionresult(controllercontext controllercontext, actionresult actionresult) +13
system.web.mvc.<>c__displayclass1a.<invokeactionresultwithfilters>b__17() +23 system.web.mvc.controlleractioninvoker.invokeactionresultfilter(iresultfilter filter, resultexecutingcontext precontext, func
1 continuation) +242
system.web.mvc.<>c_displayclass1c.b_19() +21 system.web.mvc.controlleractioninvoker.invokeactionresultwithfilters(controllercontext controllercontext, ilist1 filters, actionresult actionresult) +177
system.web.mvc.async.<>c__displayclass2a.<begininvokeaction>b__20() +89 system.web.mvc.async.<>c__displayclass25.<begininvokeaction>b__22(iasyncresult asyncresult) +102 system.web.mvc.async.wrappedasyncresult
1.end() +57 system.web.mvc.async.asynccontrolleractioninvoker.endinvokeaction(iasyncresult asyncresult) +43
system.web.mvc.<>c_displayclass1d.b_18(iasyncresult asyncresult) +14
system.web.mvc.async.<>c_displayclass4.b_3(iasyncresult ar) +23 system.web.mvc.async.wrappedasyncresult1.end() +62
system.web.mvc.controller.endexecutecore(iasyncresult asyncresult) +57 system.web.mvc.async.<>c__displayclass4.<makevoiddelegate>b__3(iasyncresult ar) +23 system.web.mvc.async.wrappedasyncresult
1.end() +62
system.web.mvc.controller.endexecute(iasyncresult asyncresult) +47
system.web.mvc.controller.system.web.mvc.async.iasynccontroller.endexecute(iasyncresult asyncresult) +10
system.web.mvc.<>c_displayclass8.b_3(iasyncresult asyncresult) +25
system.web.mvc.async.<>c_displayclass4.b_3(iasyncresult ar) +23 system.web.mvc.async.wrappedasyncresult`1.end() +62
system.web.mvc.mvchandler.endprocessrequest(iasyncresult asyncresult) +47 system.web.mvc.mvchandler.system.web.ihttpasynchandler.endprocessrequest(iasyncresult result) +9
system.web.callhandlerexecutionstep.system.web.httpapplication.iexecutionstep.execute() +9514812 system.web.httpapplication.executestep(iexecutionstep step, boolean& completedsynchronously) +155

here controller code.

namespace mvcapplication3.controllers {     public class customercontroller : controller     {         //         // get: /customer/          public actionresult index()         {             models.northwinddatacontext nwd = new models.northwinddatacontext();             return view(nwd.customers.tolist());         }      } } 

here view

<%@ page title="" language="c#" masterpagefile="~/views/shared/site.master" inherits="system.web.mvc.viewpage<mvcapplication3.models.customer>" %>  <asp:content id="content1" contentplaceholderid="titlecontent" runat="server">     index </asp:content>  <asp:content id="content2" contentplaceholderid="maincontent" runat="server">  <h2>index</h2>  </asp:content>  <asp:content id="content3" contentplaceholderid="featuredcontent" runat="server"> </asp:content>  <asp:content id="content4" contentplaceholderid="scriptssection" runat="server"> </asp:content> 

can give me hint fix it?

you're trying pass collection view that's designed single object.

change view declaration to

inherits="system.web.mvc.viewpage<ienumerable<mvcapplication3.models.customer>>


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -