Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MVC model=>model

Posted on 2014-02-26
11
Medium Priority
?
267 Views
Last Modified: 2014-03-03
Hi Expert,

I like to Create a new record in create view on person table.

I got error in Create.aspx

<%: Html.LabelFor(model => model.PersonID)%>

CS1061: 'MvcApplication2.Models.SchoolEntities' does not contain a definition for 'PersonID'

I attached other pages.

Thanks in advance for any suggestion.
Doc1.docx
0
Comment
Question by:dshi15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39891202
Hi,

In order to help you with this, i would like some more info.

1.What is the model you are using in the Create.aspx (i know it is implied you are using Person model, but i want to see what you have.

2.Can you please post your Person model definition?

Giannis
0
 
LVL 21

Expert Comment

by:Craig Wagner
ID: 39891772
Based on the code you've shown you're not passing a model to your View (i.e. return View()), so it makes sense that the view wouldn't have any idea what is in the model because there isn't one.

If you're going to render things from the model you need to create a strongly-typed view.

return View( new Person() );

You're using the WebForms view engine so I don't know what the correct syntax is, but you then need to declare your model in the view. In Razor you'd do.

@model Person

You'll need to figure out how to do that in WebForms.

I would strongly recommend you do a tutorial on MVC before you get too much farther into this development project. These are pretty fundamental questions and concepts and if you don't get a good foundation in them early you're going to have nothing but trouble later on. This would be a good starting point.

http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39891802
I need to add that it seems that your page expects a SchoolEntities model, while you are using a Person model.

Giannis
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
LVL 1

Author Comment

by:dshi15
ID: 39892015
jyparask: Where is Person model definition?

I attached screen shot for Person model properties.


CraigWagner:

I followed the online Tutorial, because my visual studio is 2010, so I used MVC2 and only change Movie table to Person table I already had

http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part6

return View( new Person() ); in screen shot page1.


thanks.
Doc1.docx
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39892348
I need to see what is on top of your Create.cshtml

So either scroll to the top of it and take a screenshot or better copy the whole code of this page and paste it in your post. Then please mark all the code in you post before submitting and then hit the code button from the tools in the post editor.

Then your code will look like this and will help us help you.

Open in new window

0
 
LVL 1

Author Comment

by:dshi15
ID: 39892485
I don't have Create.cshtml page, this is Create.aspx page, I tried People.PersonID and model.People.LastName,  no one work. I copied code below and attached screen shot too.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication2.Models.SchoolEntities>" %>

<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 => People.PersonID)%>
            </div>
            <div class="editor-field">
                <%: Html.TextBoxFor(model => model.People.LastName)%>
                <%: Html.ValidationMessageFor(model => model.LastName)%>
            </div>
           
            <div class="editor-label">
                <%: Html.LabelFor(model => model.FirstName)%>
            </div>
            <div class="editor-field">
                <%: Html.TextBoxFor(model => model.FirstName)%>
                <%: Html.ValidationMessageFor(model => model.FirstName)%>
            </div>
           
            <p>
                <input type="submit" value="Create" />
            </p>
        </fieldset>

    <% } %>

    <div>
        <%: Html.ActionLink("Back to List", "Index") %>
    </div>

</asp:Content>
Doc2.docx
0
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 2000 total points
ID: 39893015
The inherits directive you have defined in the very first line of your page dictates that your page expects a model of StudentEntities type.

So you must either change that to Person.

You may also show us your StudentEntities definition.

Giannis
0
 
LVL 1

Author Comment

by:dshi15
ID: 39893217
SchoolEntities in Web.config


<add name="SchoolEntities" connectionString="metadata=res://*/Models.Person.csdl|res://*/Models.Person.ssdl|res://*/Models.Person.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SHIDON1;initial catalog=School;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />[
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39893272
Try:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication2.Models.SchoolEntities.Person>" %>

Open in new window

0
 
LVL 1

Author Comment

by:dshi15
ID: 39895084
jyparask:

I changed to Person or People and both don't work.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication2.Models.SchoolEntities.Person>" %>

Open in new window


<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication2.Models.SchoolEntities.People>" %
0
 
LVL 1

Author Comment

by:dshi15
ID: 39901358
jyparask:

I changed to Person and removed SchoolEntities, it works now. Thank you.
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication2.Models.Person>" %

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question