Search code examples
asp.netasp.net-mvc-3html-helperrazor-declarative-helpers

Html.BeginForm() in declarative helper methods


I'm trying to create a from using Html.BeginForm() in a razor helper method in a partial page (Razor) in app_code folder . but no success .

@helper  GenerateForm(...){

 @using(@Html.BeginForm(.... // error

}

I tried adding namespaces like System.web.mvc or system.web.webpages but no difference . is it possible to use this method in this code ?


Solution

  • You should pass HtmlHelper html to this helper and use it:

    helper  GenerateForm(HtmlHelper html, ...){
    
        @using(html.BeginForm(.... // error
    
    }