ViewData does not exist... in a ViewPage?

Last post 09-17-2009 9:19 PM by xsdf. 2 replies.

Sort Posts:

  • ViewData does not exist... in a ViewPage?

    09-02-2008, 12:19 PM
    • Member
      251 point Member
    • Emyr
    • Member since 07-25-2008, 9:51 AM
    • Wales
    • Posts 82

     In the Index.aspx view of my controller, I've done this, and it works:

      

    <% foreach (MyClass item in (IEnumerable)ViewData.Model) { %>
                    <tr>
                        <td>
                            <a href="/MyController/Edit/<%= item.Id %>">
                                <%= item.GUID %>
                            </a>
                        </td>
                        <td>
                            <a href="/MyController/Edit/<%= item.Id %>">
                                <%= item.Description %>
                            </a>
                        </td>
                    </tr>
                <% } %>

     However, having attempted a copy&paste into a new action's ViewPage, I'm getting

    The name 'ViewData' does not exist in the current context
     

    WTF?!?



    originalPoster = forumthread.GetOP;
    answerPost = originalPoster.Answerfound(forumthread);
    (answerPost!=null?answerPost.markAsAnswer():originalPoster.GiveMoreInfo(forumthread));
  • Re: ViewData does not exist... in a ViewPage?

    09-02-2008, 4:52 PM
    Answer
    • Star
      14,208 point Star
    • ScottGu
    • Member since 06-05-2002, 8:36 PM
    • Redmond, WA
    • Posts 2,004
    • AspNetTeam
      Moderator

    Have you tried compiling the project?  It could be that you haven't done a compile since you added the page, and so intellisense with C# hasn't picked up that you are deriving from a base-class yet.

    Thanks,

    Scott

  • Re: ViewData does not exist... in a ViewPage?

    09-17-2009, 9:19 PM
    • Member
      4 point Member
    • xsdf
    • Member since 08-04-2008, 10:23 AM
    • Posts 13

    I have the same problem . And I confirm that I have complied the solution .

    There stilll have a warning that "ViewData" does not exist in current context .

    How can I figure it out . ?

    ************************************
    To be or not to be, it's not a question ,it's life.
Page 1 of 1 (3 items)