3

I created an ASP.NET MVC 2 project with a model. I then created a view and selected for it to be strongly-typed for the model that was created. I also did the same thing with a partial view. In either case for some reason I am getting the error: "Cannot resolve symbol 'Html' whenever I try to use the Html helper methods that ASP.NET MVC 2 provides for creating form elements for the model. I have Visual Studio 2010 and ASP.NET MVC 2 installed. Is this something that has been seen before? If so, is there a solution that will resolve this?

My model looks like:

public namespace MyNamespace { public class MyModel { public string MyProperty { get; set; } } }

The first line of my regular view is:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MyNamespace.MyModel>" %>

The first line of my partial view is:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyNamespace.MyModel>" %>
3
  • Are you using resharper by any chance? Commented Nov 8, 2010 at 18:57
  • Yes, but this happened even before I installed ReSharper. Commented Nov 8, 2010 at 19:05
  • Did you find a way to fix this? Commented Feb 17, 2011 at 10:13

5 Answers 5

5

I think I found a fix for your problem (I'm not sure if it's temporary though)

When you create a new asp mvc project it contains 2 web.config files. One on the project root and one on the Views directory.

I thought that the one on the Views wasn't required so I excluded it. The next day resharper stop recognizing the Html helper methods. I added it again and reload the solution and all errors were gone.

Hope this helps

EDIT

this link would probably help with this problem

Sign up to request clarification or add additional context in comments.

1 Comment

Old Q/A but still relevant. Another cause is if you ware using a custom view engine that is not defined properly in the View web.config. Bottom line. Make sure both of your web.config files have no errors with respect to razor or view engines in general. Will usually fix the problem.
3

I get this error all the time, I don't quite know what causes it. It must have something to do with Visual Studio failing to parse the Page / UserControl directive properly and subsequently not loading the correct type defined in the inherits attribute.

It doesn't really affect the application other than losing intellisense and you also get a lot of errors in the visual studio output when you have the aspx view file open and build your solution (your solution should still build no worries).

I can get the error to go away every now and again by messing with the Page / UserControl directive, which forces Visual Studio to re-parse it. E.g. put a random space anywhere inside the inherits attribute and then delete it.

HTHs,
Charles

Ps. I too am using resharper, but I'm not sure if it's to blame.

Comments

0

Yea, this has happened a couple times to me as well. If the application loads correctly and the view loads the objects I suspect it might be your ReSharper Build. Try updating your version of Resharper and see if it recognizes your models.

2 Comments

Like I said in the comment above, it happened before I installed ReSharper.
I had been using non-strongly-typed partial views until I tried it on another computer. Today I tried to build and run an app with the strongly-typed view (ignoring that the Html helper was read) and got it to compile. When I navigated to the site I got a different error. It seems that it failed to find the model somehow... It might be an error on my part though.
0

I've had the same issue, also removed the web.config in a moment of ignorance...

Merging the below piece of the web.config to your web.config in the root of the web application will do the trick also. It's works again like it should and still you have only one web.config file.

  <system.web>
     <pages
          validateRequest="false"
          pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
          pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
          userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
        <controls>
           <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
        </controls>
    </pages>
  </system.web>

Comments

0

This error happened to me because I moved by mistake the web.config that was inside the "Views" folder. This file contains the include of System.Web.Mvc. Hope this helps.
Greetings

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.