如何创建强类型的BeginForm? [英] How do I create a strongly typed BeginForm?
问题描述
我已经看到一些使用HTML.BeginForm语法的人的例子:
I've seen a few examples of people using this syntax for HTML.BeginForm:
(Html.BeginForm<Type>(action => action.ActionName(id)))
但是当我尝试这种语法时,我得到的只是一个:
But when I try this syntax all I get is a:
The non-generic method System.Web.Mvc.Html.FormExtensions.BeginForm(System.Web.Mvc.HtmlHelper)'
cannot be used with type arguments
我想念什么? Visual Studio 2010,System.Web.MVC版本是v2.0.50727
What am I missing? Visual Studio 2010, System.Web.MVC version is v2.0.50727
推荐答案
您将在 MVCContrib ,尤其是在Microsoft.Web.Mvc.FormExtensions
类的Microsoft.Web.Mvc.dll
程序集中.因此,请下载该程序集并将其包含在您的项目中,并在web.config文件的namespaces
部分中添加Microsoft.Web.Mvc
命名空间:
You will find this extension methods in MVCContrib and more specifically in the Microsoft.Web.Mvc.dll
assembly in the Microsoft.Web.Mvc.FormExtensions
class. So download and include this assembly in your project and add the Microsoft.Web.Mvc
namespace in the namespaces
section of your web.config file:
<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="System.Linq"/>
<add namespace="System.Collections.Generic"/>
<add namespace="Microsoft.Web.Mvc"/>
</namespaces>
,您将可以在视图中使用它.
and you will be able to use it in your views.
这篇关于如何创建强类型的BeginForm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!