【问题标题】:What is the syntax for a strongly-typed ActionLink in MVC 4 with MVC 4 Futures?MVC 4 中带有 MVC 4 期货的强类型 ActionLink 的语法是什么?
【发布时间】:2013-08-13 18:22:35
【问题描述】:

我在 Visual Studio 2012 中使用新的 MVC 4 Internet 应用程序模板。我已经为 MVC 4 Futures 安装了 Nuget 包。在我的_Layout.cshtml 中,我正在构建导航菜单。

这有效并构建了正确的 URL:

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

这就是我想要的工作,一个强类型的变体:

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

它对“无法从方法组中选择方法。你的意思是调用一个方法吗?”感到悲伤,但有件事告诉我这不是真正的问题。

这会编译并输出正确的 HTML,但不是内联的:

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

如何使用 Razor 的语法(有或没有 Futures)在 MVC 4 中构建强类型的 Action/ActionLink?

【问题讨论】:

  • 我读了很多关于 asp.net mvc 的书,但从未见过强类型操作链接,谢谢你的好问题。

标签: .net asp.net-mvc-4 razor-2 asp.net-mvc-futures


【解决方案1】:
@(Html.ActionLink<CustomersController>(x => x.Index(), "Customers"))

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

这个question 松散地覆盖了它。

【讨论】:

  • 这个语法在MVC中是否还存在,我好像找不到了。
  • 应该提到需要添加对 Microsoft.Web.Mvc 及其控制器 (MyWebApp.Controllers) 的引用
  • 这个选项在更新的 .NET 框架中还存在吗?
猜你喜欢
  • 2010-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多