2

我想app_code文件夾中的partial page (Razor)剃刀輔助方法,使用Html.BeginForm()創建一個from。但沒有成功。Html.BeginForm()在聲明輔助方法

@helper GenerateForm(...){ 

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

} 

我嘗試添加命名空間像System.web.mvcsystem.web.webpages但沒有什麼區別。 是否有可能使用這個方法在這個代碼

+0

可能重複的是,爲什麼爲HtmlHelper比如在空Razor聲明式@helper方法?](http://stackoverflow.com/questions/5282655/why-is-the-htmlhelper-instance-null-in-a-razor-declarative-helper-method) – nemesv

+0

HtmlHeLper不爲null但它並不包含所有的方法,因爲它在視圖 –

回答

2

您應該傳遞的HtmlHelper HTML這個幫手,並使用它:

helper GenerateForm(HtmlHelper html, ...){ 

    @using(html.BeginForm(.... // error 

} 
的[
0

試試這個:@using(Html.BeginForm(...

+0

它沒有區別 –

+0

好吧,這裏是我使用htmlhlper的良好代碼的示例:@using( Html.BeginForm( 「上傳」, 「上載」,FormMethod.Post,新的{ENCTYPE = 「多部分/格式數據」})) { @ Html.ValidationSummary(真)

選擇文件<輸入type =「file」name =「file」/>
} – Nathan