-
April 5th, 2017, 10:44 AM
#1
MVC: View error for a single item
I'm new to MVC and might not explain myself well.
I've got a controller method that returns a single data item.
var insp = DC.Inspections.FirstOrDefault(x => x.pKey == pKey);
I've tried that as a strongly typed item, as well as a var. It doesn't matter.
when I get to the view, I get the following error:
'IEnumerable<Inspection>' does not contain a definition for 'ProjectName' and no extension method 'ProjectName' accepting a first argument of type 'IEnumerable<Inspection>' could be found
This is because in the view, I reference one of the fields from the model:
@Html.Label(Model.ProjectName, new { id = "lblProject" })
the view specifies the model as:
@model IEnumerable<XYZ.Models.Inspection>
I understand that the issue is that the model is an IEnumerable. How can I specify the model as a single instance of the type I want?
-
April 5th, 2017, 08:16 PM
#2
Re: MVC: View error for a single item
The model should be defined as
Code:
@model XYX.Models.Inspection
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|