What is the syntax for a strongly-typed ActionLink in MVC 4 with MVC 4 Futures?

只愿长相守 提交于 2019-12-18 03:58:42

问题


I am using a new MVC 4 Internet application template with Visual Studio 2012. I have installed the Nuget package for MVC 4 Futures. In my _Layout.cshtml I am building the navigation menu.

This works and builds the correct URL:

@Html.ActionLink("Customers", "Index", "Customers")

This is what I would like to work, a strongly-typed variation:

@Html.ActionLink<CustomersController>(c => c.Index(), "Customers", null)

It griefs on "Cannot choose method from method group. Did you mean to invoke a method?", but something tells me that's not the real issue.

This compiles and outputs the right HTML, but not inline:

@{
   var t = Html.ActionLink<CustomersController>(c => c.Index(), "Customers");
   Response.Write(t);
}

How do you build strongly-typed Action/ActionLink's in MVC 4 using Razor's syntax (with or without Futures)?


回答1:


@(Html.ActionLink<CustomersController>(x => x.Index(), "Customers"))

The Basics – (Strongly-Typed) Linking to MVC Actions

This question covers it loosely.



来源:https://stackoverflow.com/questions/18216413/what-is-the-syntax-for-a-strongly-typed-actionlink-in-mvc-4-with-mvc-4-futures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!