views:

27

answers:

2

I use <%= Html.Action("ReadXML") %> and have this error:

'System.Web.Mvc.HtmlHelper' does not contain a definition for 'Action' and no extension method 'Action' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

How fix it

This is my assemblies:

   <assemblies>
    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

  </assemblies>
A: 

Make sure there is a reference to System.Web.Mvc in your project (add it if not already there).

Then make sure the class that is displaying this problem is importing the namespace - you can do this in a couple of ways:

  • In the code behind add a using System.Web.Mvc; statement at the top.
  • You can also import the namespace directly in the aspx page if needed, by using this statement: <%@ import namespace="System.Web.Mvc"%>
Oded
I already import namespace but problem is not gone
Ognjen
A: 

Action is an extension method contained in the System.Web.Mvc assembly. Make sure you have referenced the following namespaces in your web.config:

<pages>
  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
  </namespaces>
</pages>

The method is declared in the System.Web.Mvc.Html namespace.

Also make sure your project is ASP.NET MVC 2.0 as this method has been added in the 2.0 version.

Darin Dimitrov
I have that namespaces in web.config
Ognjen
Are you using ASP.NET MVC 2.0, the `System.Web.Mvc` assembly version should be 2.0.0.0?
Darin Dimitrov
Yes, i am using ASP.NET MVC 2.0
Ognjen
I have installed ASP.NET MVC 2 Preview 2,is this problem
Ognjen
ASP.NET MVC 2.0 is RTM now. Why installing betas and preview versions when you could use the final release? I am not sure in which of the betas this method has been introduced. What is sure is that it didn't exist in 1.0 RTM and that it exists in 2.0 RTM. You could explore the `System.Web.Mvc` assembly you are using with reflector to verify the non-presence of this extension method.
Darin Dimitrov
Ognjen