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

1

13

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

Synthesis answered 13/8, 2013 at 18:22 Comment(1)
I read many books about asp.net mvc, but never saw strongly type action link, thanks for good question.Subacute
C
6
@(Html.ActionLink<CustomersController>(x => x.Index(), "Customers"))

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

This question covers it loosely.

Cade answered 13/8, 2013 at 18:42 Comment(3)
does this syntax still exist in MVC , I can't seem to find it.Buffum
Should mention one needs to add references to Microsoft.Web.Mvc and to their controllers (MyWebApp.Controllers)Chemulpo
Does this option still exist in more recent .NET frameworks?Utopia

© 2022 - 2024 — McMap. All rights reserved.