編輯:我忘了提及既沒有ActionLink <>或BeginForm <>已經工作過我,我有最新的MVC版本(查看可用的更新來自NUGET的項目,mvc不在推薦列表中)。有沒有使用此功能的示例教程/示例?Html.BeginForm(「Index」,「CustomersController」)不使用字符串
在問題「What is an alternative to using strings for action and controller names in asp.net MVC?」我收到的答案,使用此答案What is the syntax for a strongly-typed ActionLink in MVC 4 with MVC 4 Futures?
我試圖做什麼,他們有例如動作鏈接完成:
@(Html.ActionLink<CustomersController>(x => x.Index(), "Customers"))
但類似的甚至沒有編譯:
Html.BeginForm<CustomersController>(x => x.Index())
有一些命名空間,我需要添加或不同的語法我需要嘗試?
更新2:這是我有:
@using (Html.BeginForm<UnitTestsController>(x => x.Index()))
UnitTestsController是refereced OK,智能感知甚至不會讓X => x.Index()),我不停地拍它
。還增加System.Linq
命名空間,但是沒有被使用(通過整形器變灰) 在運行時的錯誤是:
編譯器錯誤消息:CS0308:非通用方法「System.Web.Mvc.Ajax。 AjaxExtensions.BeginForm(System.Web.Mvc.Aj axHelper,字符串,字符串,System.Web.Routing.RouteValueDictionary,System.Web.Mvc.Ajax.AjaxOptions,System.Collections.Generic.IDictionary)'不能與類型參數一起使用
哪一個正在使用 - T4MVC或MVC4期貨? –
@StephenMuecke MVC4 – Arjang
您是否包含'Microsoft.Web.Mvc'命名空間?關於「期貨」項目的信息,請參閱[本答案](http://stackoverflow.com/questions/35329402/system-web-mvc-vs-microsoft-web-mvc/35330351#35330351) –