0

Yes I've searched the rest of s.o. for a solution, none of those solutions worked for me. Here's the issue:

1) Visual Studio 2012 -> New Web Site...

2) create a normal MVC 4 site (Razor v2) and .NET 4.5

3) add the following code to Default.cshtml

@using (Html.BeginForm())
{

}

4) launch and get this error:

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

What gives?

EDIT, uploaded my website here as a zip, only 276K: http://budzap.com/mvc.zip

R-D
  • 566
  • 6
  • 13
  • It would help if you listed what's been tried: using statement exists, cleaned solution, removed .user project file, NUGET restore, etc. http://stackoverflow.com/questions/12692011/system-web-mvc-htmlhelper-does-not-contain-a-definition-for-actionlink – Steve Greene Apr 22 '15 at 19:57
  • have you tried updating the web.config as seen here http://stackoverflow.com/questions/12041633/razor-views-not-seeing-system-web-mvc-htmlhelper – Matchbox2093 Apr 22 '15 at 20:35
  • I tried about 20 various solutions across s.o., so didn't want to list them all but really nothing has helped. Tried goldeneye's fix but no effect. Added a link to a zip of my website, maybe someone can try running it real quick and get the same error. – R-D Apr 23 '15 at 15:51
  • Could u create solution and upload to the site. – Cherry Apr 23 '15 at 15:55
  • Did already, it's at the bottom of the question, here too: http://budzap.com/mvc.zip – R-D Apr 23 '15 at 19:02

3 Answers3

2

Make sure that the Razor version number in Views > Web.config match each other.

<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0 [etc]

and

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0 [etc]
Hugh Seagraves
  • 594
  • 1
  • 8
  • 14
  • heh about 4 years too late, we don't even use BeginForm anymore but thx – R-D Jan 14 '19 at 21:33
  • Thanks buddy Hugh Seagraves – user1638526 Aug 28 '20 at 14:04
  • @Huge you are right - this is the case for me - System.Web.WebPages.Razor is 3.0.0.0 while System.Web.MvcSystem.Web.Mvc is 4.0.0.0 but how do I fix it? the PM says both are latest and just change manually gives of course an error. Thanks. – Qua285 Oct 08 '20 at 06:29
0

This message says the version of your System.Web.Mvc does not support BeginForm.It may have many causes.To find out the cause your problem,you can try one of this:

  • It is usaually caused by deleting the second web.confing which resides in the view folder.see this

  • See the version of your System.Web.Mvc in References of your project.it might be an old version that doesnot support BeginForm.

  • add System.Web.Mvc.html before BeginForm to see if there is such a method.

Community
  • 1
  • 1
Nima Habibollahi
  • 360
  • 5
  • 16
-2

Move your _layoutPage into the Views folder