asp.net - Wrong model item passed (with partial view) -


i working asp.net mvc 2 , vs 2010. , have 2 views:
view1 creating record in database.
view2 listing data database.

i trying merge views see them in 1 .aspx file using 4 .aspx files:
views/shared/view1.aspx
views/shared/view2.aspx
views/home/index.aspx (here goes code partial view)
views/shared/chartlayout.master (this 1 not essential @ all, it's css testing)

error: model item passed dictionary of type 'system.data.objects.objectset`1[bookingapp.models.bookingtableset]', dictionary requires model item of type 'bookingapp.models.bookingtableset'.

everything works fine if leave view1 blank.

here's code,

index.aspx:

<%@ page language="c#" masterpagefile="~/views/shared/site.master" inherits="system.web.mvc.viewpage" %> <asp:content id="indextitle" contentplaceholderid="titlecontent" runat="server"> home page </asp:content>  <asp:content id="indexcontent" contentplaceholderid="maincontent" runat="server"> <h2><%= html.encode(viewdata["message"]) %></h2> <div style="float:left"><%html.renderpartial("view1"); %></div> <div style="float:left"><%html.renderpartial("view2"); %></div> <div style="clear:both"> </div>   </asp:content>  


view1.aspx:

<%@ page title="" language="c#" masterpagefile="~/views/shared/site.master"      inherits="system.web.mvc.viewpage<bookingapp.models.bookingtableset>"  %> <asp:content id="content1" contentplaceholderid="titlecontent" runat="server"> create </asp:content> <asp:content id="content2" contentplaceholderid="maincontent" runat="server"> <h2>create</h2> <% using (html.beginform()) {%>     <%: html.validationsummary(true) %>      <fieldset>         <legend>fields</legend>          <div class="editor-label">             <%: html.labelfor(model => model.id) %>         </div>         <div class="editor-field">             <%: html.textboxfor(model => model.id) %>             <%: html.validationmessagefor(model => model.id) %>         </div>          <div class="editor-label">             <%: html.labelfor(model => model.name) %>         </div>         <div class="editor-field">             <%: html.textboxfor(model => model.name) %>             <%: html.validationmessagefor(model => model.name) %>         </div>          <div class="editor-label">             <%: html.labelfor(model => model.quality) %>         </div>         <div class="editor-field">             <%: html.textboxfor(model => model.quality) %>             <%: html.validationmessagefor(model => model.quality) %>         </div>          <div class="editor-label">             <%: html.labelfor(model => model.isbooked) %>         </div>         <div class="editor-field">             <%: html.textboxfor(model => model.isbooked) %>             <%: html.validationmessagefor(model => model.isbooked) %>         </div>          <div class="editor-label">             <%: html.labelfor(model => model.databooked) %>         </div>         <div class="editor-field">             <%: html.textboxfor(model => model.databooked) %>             <%: html.validationmessagefor(model => model.databooked) %>         </div>          <div class="editor-label">             <%: html.labelfor(model => model.timebooked) %>         </div>         <div class="editor-field">             <%: html.textboxfor(model => model.timebooked) %>             <%: html.validationmessagefor(model => model.timebooked) %>         </div>         <p>             <input type="submit" value="create" />         </p>     </fieldset> <% } %> <div>     <%: html.actionlink("back list", "index") %> </div> </asp:content> 


bet has inheritance have no idea what. help.

edit
site.master:

<%@ master language="c#" inherits="system.web.mvc.viewmasterpage" %> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"   "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title><asp:contentplaceholder id="titlecontent" runat="server" /></title> <link href="../../content/site.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="page">     <div id="header">         <div id="title">             <h1>my mvc application</h1>         </div>                       <%-- %> <div id="logindisplay">             <% html.renderpartial("logonusercontrol"); %>         </div> %>                     <div id="menucontainer">                      <%-- %> <ul id="menu">                               <li><%: html.actionlink("home", "index", "home")%></li>                  <li><%: html.actionlink("about", "about", "home")%></li>              </ul> --%>                   </div>     </div>     <div id="main">         <asp:contentplaceholder id="maincontent" runat="server" />         <div id="footer">         </div>     </div> </div> </body> </html> 

controller:

[httppost]     public actionresult create([bind(exclude = "id")] bookingtableset movietocreate)     {         if (!modelstate.isvalid)             return view();          _db.addtobookingtablesets(movietocreate);         _db.savechanges();         return redirecttoaction("index");     } 

edit2:

basically have these 2 tutorials meerged together: http://www.asp.net/mvc/tutorials/older-versions/movie-database/create-a-movie-database-application-in-15-minutes-with-asp-net-mvc-cs

http://jeffreypalermo.com/blog/asp-net-mvc-and-the-templated-partial-view-death-to-ascx/

maybe understand i'm trying do.

you need pass model explicitly html.renderpatial("view1", model.bookingset);

where bookingset model required view1

the view data dictionary passed controllers view has 1 model , aspx view1 expecting model of different type


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -