Html.BeginForm() with Razor Generator

11,654

Solution 1

It's most likely a namespacing or reference issue.

First, check to make sure that System.Web.WebPages shows up in your project references. Then add

@using System.Web.WebPages

to the top of your view. If that fixes it, you can move the reference into the web.config per this answer on the same type of topic

Solution 2

For me it was a missing namespace, yes, but not the one mentioned by eouw0o83hf:

@using System.Web.Mvc.Html;

Solution 3

Please post your code when you ask a question so we can see what you're doing wrong. Try this:

 @using (Html.BeginForm()) {
        <input type="radio"/>
        <input type="radio"/>
}
Share:
11,654
kbaccouche
Author by

kbaccouche

Problem Exists Between Keyboard And Chair [PEBKAC]

Updated on June 04, 2022

Comments

  • kbaccouche
    kbaccouche almost 2 years

    I am making a Helper with razor generator to build a cutom control in which there will be two radio buttons (yes/no) I want to use Html.BeginForm for this.

    But can't do it.

    Do you know how to do it or another way to do it ?

    Thanks.

    Edit :

    When I put this code

    @using (Html.BeginForm()) {
        <input type="radio"/>
        <input type="radio"/>
    }
    

    I get this error

    'System.Web.WebPages.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 
    
    • eouw0o83hf
      eouw0o83hf about 12 years
      What do you mean you "can't do it"? Is there an error message?
    • kbaccouche
      kbaccouche about 12 years
      'System.Web.WebPages.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
  • trevorgk
    trevorgk about 9 years
    Irritating to have to include these references in each helper method, and have Resharper complain about variable obfuscation etc