Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

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

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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
@(Html.ActionLink<CustomersController>(x => x.Index(), "Customers"))

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

This question covers it loosely.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...