score:2
Try this(your code does not work because of you view wait for ContentPageNav item but you send a list of ContentPageNav):
public ActionResult Edit()
{
using(DataClasses1DataContext dc = new DataClasses1DataContext())
{
// here you can select some specific item from the ContentPageNavs list
// Following query take first item from the list
var model = dc.ContentPageNavs.FirstOrDefault();
return View(model);
}
}
score:6
You are selecting a list of ContentPageNav
into your model
variable.
The view is expecting a ContentPageNav
, not a list of them.
Try this:
var model = (from m in dc.ContentPageNavs
select m).FirstOrDefault();
score:2
As the error indicates the types don't match. The view expects a single item but you are passing in a collection of items. Try passing this in as the model : (from m in dc.ContentPageNavs select m).FirstOrDefault();
score:4
It looks like your page is expecting a single ContentPageNav, not a LINQ expression. Try
return View(model.FirstOrDefault());
or
var model = dc.ContentPageNavs.FirstOrDefault();
score:2
Have a look at your view it is strongly typed. It should say something like
Inherits="System.Web.Mvc<ContentPageNav>"
if you need a list you may want to consider using
Inherits="System.Web.Mvc<IList<ContentPageNav>>"
or some kind of list ... your LINQ might be wrong though if this is not intended.
Source: stackoverflow.com
Related Articles
- MVC gives a strange error
- LINQ Max extension method gives an error on empty collections
- Linq functions give strange compile error when ambiguous use of IEnumerable - possible workarounds?
- Is there a good source that gives an overview of linq optimizations?
- reading a empty cell, gives object reference error
- MS CRM 2011 CrmSvcUtil gives error
- LINQ query with two joins that worked in EF 6 gives error in EF 7
- Linq to SQL insert with primary key as tinyint set to auto-increment gives error message
- LINQ Source Code Available
- .NET 4 Code Contracts: "requires unproven: source != null"
- EF Code First comparing null values generates strange query
- Strange Linq Error
- creating Linq to sqlite dbml from DbLinq source code
- LINQ to List<T> gives an error
- Fetching only required columns from table using LINQ to modify and save record gives a typical error
- Conversion of Expression with nullable DateTime gives an error
- C# OrderBy and iOS gives JIT error
- ProtoBuf-Linq error message “ Invalid field in source data: 0”
- Getting "Could not find an implementation of the query pattern for source type 'ExcelQueryable<T>'. " Error
- Error when using XDocument in code behind
- EF Code First Insert Objects with One to Many gives exception."Store update, insert, or delete statement affected an unexpected number of rows (0)."
- LINQ entity data model generated code error - The type 'DBContexts.Category' already contains a definition for 'ID'
- ASP.Net LINQ data source error is ListView
- why gives error Expression cannot contain lambda expressions?
- Compiling Error with LINQ Sorting Code Using List<T>
- source code for LINQ 101 samples
- .Where in list gives error for using dynamic types in 2sxc
- Adding a second query inside the SELECT of a LINQ to Entities query gives Not Recognized Method error
- CRM 2011 - Compare years in LINQ Query - Gives an error : Invalid 'where' condition. An entity member is invoking an invalid property or method
- Strange LINQ query error
- Linq Where Inside Include
- Find project by Person Category
- Set and use value in linq query
- Calculate maximum number of open events
- LINQ return records where string[] values match Comma Delimited String Field
- String replacement with linq
- Refresh DataSource after SaveChange does not work
- Initialie a Query
- Entity Framework: best practice to filter data inside multiple "one-to-many" relationships
- How to improve Query with linq
- LINQ to SQL and a running total on ordered results
- Easier way to populate a list with integers in .NET
- Return final result from stored procedure in Entity Framework
- is there anyway this LINQ could end up doing too much work?
- Difference of a set of floating-point numbers using LINQ
- linq GroupBy with Where
- Converting string to nullable DayOfWeek field using Linq cause an error
- Nullable entity projection in Entity Framework
- Linq OrderBy sort rule
- How to create a lambda expression from a type object with LINQ?