Why can't I use Html helper methods with strongly typed views in ASP.NET MVC 2?

I created an ASP.NET MVC 2 project with a model. Then I created the view and selected it for strongly typed for the created model. I also did the same with a partial view. In any case, for some reason I get the error message: "It is not possible to resolve the" Html "symbol 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. Is this something that has been noticed before? If so, is there a solution that will resolve this?

My model looks like this:

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

The first line of my regular view:

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

The first line of my partial :

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyNamespace.MyModel>" %>
+3
source share
5 answers

I think I found a fix for your problem (I'm not sure if this is temporary)

When you create a new asp mvc project, it contains 2 web.config files. One at the root of the project and one in the catalog of views.

I thought that the one in the Views was not required, so I excluded it. The next day, resharper will stop recognizing Html helper methods. I added it again and reloaded the solution and all errors disappeared.

Hope this helps

EDIT

this link will probably help with this problem

+5
source

, , . , Visual Studio Page/UserControl, , inherits.

, intellisense, , aspx ( ).

, , Page/UserControl, Visual Studio . . - inherits, .

HTHS,

Ps. resharper, , .

+3

, . , , , , ReSharper Build. Resharper , .

0

, web.config ...

web.config web.config - . , , web.config.

  <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>
0

This error occurred to me because I mistakenly mistook web.config, which was inside the Views folder. This file contains include System.Web.Mvc. Hope this helps. Greetings

0
source

Source: https://habr.com/ru/post/1773679/


All Articles