dshi15
asked on
MVC model=>model
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.Sc hoolEntiti es' does not contain a definition for 'PersonID'
I attached other pages.
Thanks in advance for any suggestion.
Doc1.docx
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.Sc
I attached other pages.
Thanks in advance for any suggestion.
Doc1.docx
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
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
I need to add that it seems that your page expects a SchoolEntities model, while you are using a Person model.
Giannis
Giannis
ASKER
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
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
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.
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.
ASKER
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/Sh ared/Site. Master" Inherits="System.Web.Mvc.V iewPage<Mv cApplicati on2.Models .SchoolEnt ities>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Titl eContent" runat="server">
Create
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Main Content" runat="server">
<h2>Create</h2>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(tru e) %>
<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
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Sh
<asp:Content ID="Content1" ContentPlaceHolderID="Titl
Create
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Main
<h2>Create</h2>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(tru
<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(
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.FirstName)%>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.FirstName)%>
<%: Html.ValidationMessageFor(
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
Doc2.docx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SchoolEntities in Web.config
<add name="SchoolEntities" connectionString="metadata =res://*/M odels.Pers on.csdl|re s://*/Mode ls.Person. ssdl|res:/ /*/Models. Person.msl ;provider= System.Dat a.SqlClien t;provider connection string="data source=SHIDON1;initial catalog=School;integrated security=True;multipleacti veresultse ts=True;Ap p=EntityFr amework&qu ot;" providerName="System.Data. EntityClie nt" />[
<add name="SchoolEntities" connectionString="metadata
Try:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication2.Models.SchoolEntities.Person>" %>
ASKER
jyparask:
I changed to Person or People and both don't work.
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Sh ared/Site. Master" Inherits="System.Web.Mvc.V iewPage<Mv cApplicati on2.Models .SchoolEnt ities.Peop le>" %
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>" %>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Sh
ASKER
jyparask:
I changed to Person and removed SchoolEntities, it works now. Thank you.
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>" %
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