TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sonal malhotra
NA
410
51.9k
does not work with include method (model)in mvc
Feb 25 2019 4:47 AM
hi everyone ,
i am giving u code here below
controller
using
System;
using
System.Collections.Generic;
using
System.Data;
using
System.Data.Entity;
using
System.Linq;
using
System.Net;
using
System.Web;
using
System.Web.Mvc;
using
onlineshopping_sonal.Models;
public
ActionResult Index()
{
//var itemtable = db.Itemtables.ToList();
var items = db.Itemtables.Include(i => i.categoryTable).Include(i => i.prodtbl);
return
View(items.ToList());
}
index.cshtml
@model IEnumerable
<
onlineshopping_sonal.Models.Itemtable
>
@{
ViewBag.Title
=
"Index"
;
Layout
=
"~/Views/Shared/_Layout.cshtml"
;
}
<
h2
>
Index
</
h2
>
<
p
>
@Html.ActionLink("Create New", "Create")
</
p
>
<
table
class
=
"table"
>
<
tr
>
<
th
>
@Html.DisplayNameFor(
model
=
>
model.categoryTable.CategoryName)
</
th
>
<
th
>
@Html.DisplayNameFor(
model
=
>
model.prodtbl.Productname)
</
th
>
<
th
>
@Html.DisplayNameFor(
model
=
>
model.Title)
</
th
>
<
th
>
@Html.DisplayNameFor(
model
=
>
model.Price)
</
th
>
@*
<
th
>
@Html.DisplayNameFor(
model
=
>
model.ItemUrl)
</
th
>
*@
<
th
>
</
th
>
</
tr
>
@foreach (var item in Model) {
<
tr
>
<
td
>
@Html.DisplayFor(
modelItem
=
>
item.categoryTable.CategoryName)
</
td
>
<
td
>
@Html.DisplayFor(
modelItem
=
>
item.prodtbl.Productname)
</
td
>
<
td
>
@Html.DisplayFor(
modelItem
=
>
item.Title)
</
td
>
<
td
>
@Html.DisplayFor(
modelItem
=
>
item.Price)
</
td
>
@*
<
td
>
@Html.DisplayFor(
modelItem
=
>
item.ItemUrl)
</
td
>
*@
<
td
>
@Html.ActionLink("Edit", "Edit", new {
id
=
item
.ItemId }) |
@Html.ActionLink("Details", "Details", new {
id
=
item
.ItemId }) |
@Html.ActionLink("Delete", "Delete", new {
id
=
item
.ItemId })
</
td
>
</
tr
>
}
</
table
>
error shown below
Server Error in '/' Application.
A specified Include path is not valid. The EntityType 'shop_cartModel.Itemtable' does not declare a navigation property with the name 'categoryTable'.
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: A specified Include path is not valid. The EntityType 'shop_cartModel.Itemtable' does not declare a navigation property with the name 'categoryTable'.
Source Error:
Line 22: //var itemtable = db.Itemtables.ToList(); Line 23: var items = db.Itemtables.Include(i => i.categoryTable).Include(i => i.prodtbl); Line 24: return View(items.ToList()); Line 25: Line 26: }
Source File: C:\Users\admin\documents\visual studio 2015\Projects\onlineshopping_sonal\onlineshopping_sonal\Controllers\StoreManagerController.cs Line: 24
Stack Trace:
... any idea ? any soulution to us?
Reply
Answers (
2
)
header freeze mvc html
MapR connector from C#