views:

265

answers:

1

As of recent, a few of my strongly typed views randomly (w/ zero code changes) decided that 'Model' was not a valid item ... again - ZERO code changes. I simply opened my view and now it's broken ... so logically I deleted the view and created a new one - still broken. Has anyone else come across this issue using MVC? A simple example is below

<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of IEnumerable (Of Project.Library.Entity.User))" %>

    <table id="tblUser" cellspacing="0" cellpadding="0" border="0">
        <tr>
            <th>Username</th>
        </tr>
        <% For Each item In Model%>
        <tr>
            <td>
                <%=Html.Encode(item.Username)%>
            </td>
        </tr>
        <% Next%>
      </table>

The actual error shows up in the view - under the word "Model" is a red line and when I hover over this (in any of my partial views - strongly typed) it says "Name 'Model' is not declared"

+2  A: 

'Model' is a property of the ViewUserControl class, so when it's marked as not declared this may mean the following:

  1. There is no such property in ViewUserControl. This can be when an old version of System.Web.Mvc is used. To check this just try to delete the reference to System.Web.Mvc, and add it again and run the application. If the error in editor still exists, see case 2.
  2. Some of the plugins think that there is no such method. Or aliens hacked your VS. You can try to reload the VS or to repair it and after repair ASP.NET MVC.

Hope this will help.

zihotki