Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 955
shanabus Avatar asked Aug 13 '13 18:08

shanabus


People also ask

How can we call post method using ActionLink in MVC?

ActionLink is rendered as an HTML Anchor Tag (HyperLink) and hence it produces a GET request to the Controller's Action method which cannot be used to submit (post) Form in ASP.Net MVC 5 Razor. Hence in order to submit (post) Form using @Html. ActionLink, a jQuery Click event handler is assigned and when the @Html.

What is ActionLink in C#?

ActionLink(HtmlHelper, String, String, Object, Object)Returns an anchor element (a element) for the specified link text, action, route values, and HTML attributes. C# Copy.

What is ActionLink in MVC?

ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action. Here are some samples of Html.


1 Answers

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

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

This question covers it loosely.

like image 154
w00ngy Avatar answered Oct 01 '22 07:10

w00ngy