MVC: View error for a single item
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: MVC: View error for a single item

  1. #1
    Join Date
    Jul 2005
    Posts
    2

    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?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,586

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)