加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

.net – MVC 4中MVC 4中强类型ActionLink的语法是什么?

发布时间:2020-12-15 23:04:01 所属栏目:asp.Net 来源:网络整理
导读:我正在Visual Studio 2012中使用一个新的MVC 4 Internet应用程序模板.我已经安装了用于MVC 4期货的Nuget软件包.在我的_Layout.cshtml中,我正在构建导航菜单. 这可以正常工作并构建正确的URL: @Html.ActionLink(“Customers”,“Index”,“Customers”) 这是
我正在Visual Studio 2012中使用一个新的MVC 4 Internet应用程序模板.我已经安装了用于MVC 4期货的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的语法(有或没有期货)在MVC 4中构建强类型的Action / ActionLink?

解决方法

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

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

这个question是宽松的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读