Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HtmlHelper does not contain a definition for BeginForm

Although my code compiles and runs I am plagued by little red squiggly lines. For example, Html.BeginForm is not recognised. Although, if I type "Html." then intellisense does suggest some other methods such as Checkbox and DropDownList.

Other underlines include model and ViewBag.

I've got a reference to MVC 5.2.3.0 and the System.Web.Mvc namespace is in my web.config

This has been going on for months and is wasting a lot of my time. I'm sure it has something to do with the versions of packages I have installed but I don't understand it enough to be able to troubleshoot it.

I've rebuilt my computer, reinstalled Visual Studio 2013, and copied my code back (in chunks to try to isolate the problem) but I'm getting nowhere fast.

Can anyone help me get to the bottom of this before I switch careers?

like image 560
lonelyoutpost Avatar asked Oct 11 '16 09:10

lonelyoutpost


People also ask

What is BeginForm?

"BeginForm()" is an extension method for both HtmlHelper and AjaxHelper classes. It returns an MVCForm object from both HtmlHelper and AjaxHelper class instances so there is not much difference but the AjaxHelper method submits the form asynchronously using JavaScript.

What is the use of BeginForm?

BeginForm(HtmlHelper, String, String, FormMethod, Object)Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method and includes the HTML attributes.


2 Answers

make sure you have both, the controller and action method name in the BeginForm Method.

@using (Html.BeginForm(ActionmethodName, ControllerName, FormMethod.Post))
{
}
like image 103
Pendkar sai kiran Avatar answered Oct 13 '22 20:10

Pendkar sai kiran


Mostly like is your config problem. Make sure your Views folder's t web.config have config like this:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="SixAnts" />
      </namespaces>
    </pages>
  </system.web.webPages.razor> 

using the version of your packges and your namespace

like image 24
Bucketcode Avatar answered Oct 13 '22 19:10

Bucketcode