Patrice Calve

Life's short, have fun
posts - 51, comments - 49, trackbacks - 31

My Links

News

Archives

Post Categories

Image Galleries

ASP.Net MVC Beta - ActionLink isn't generic anymore

Hi,

I just "migrated" from ASP.Net MVC Preview 5 to ASP.Net MVC Beta.  I uninstalled Preview 5 and installed the Beta.  I already had checked out previous previews but spent the most time with Preview 5, and didn't want to upgrade my "Preview-5-version-of-my-test-website" just in case there were deprecated or new features, specially in the "New ASP.Net MVC Application" template.  Gutt feeling.  So I created a new Project.

In Preview 5 release, the Html.ActionLink accepted a generic parameter list, with lambda expression, allowing to strongly-type the controller and it's method, including its parameters.  I really like this right now (my bubble may blow one day).

The syntax would look like this:

 <%= Html.ActionLink<CalveNet.Controllers.PatwareController>(c => c.Index(), "Here")%>

After creating my project, I copied a few files over (aspx pages, controllers, etc.).  But Visual Studio complained that the

"The non-generic method 'System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, string, string)' cannot be used with type arguments"

I found out that this generic/lambda version of the parameter is from a separate dll, called "ASP.NET MVC Beta Futures". 

To make it work, unzip the file, include the "Microsoft.Web.Mvc.dll" to your references, and don't forget to include the namespace in your web.config, under the path:

/configuration/system.web/pages/namespaces

add the following: <add namespace="Microsoft.Web.Mvc"/>

Pat

Print | posted on Thursday, October 30, 2008 8:09 PM |

Feedback

Gravatar

# re: ASP.Net MVC Beta - ActionLink isn't generic anymore

Thanks very much for this post Pat.

I just did some frantic googling when all my strongly typed links and forms broke!

Thanks again.
11/9/2008 2:47 PM | Jason Summers
Gravatar

# re: ASP.Net MVC Beta - ActionLink isn't generic anymore

Thank you.
11/11/2008 9:01 AM | Charles
Gravatar

# re: ASP.Net MVC Beta - ActionLink isn't generic anymore

Thank you!
11/11/2008 11:30 AM | Gab
Gravatar

# re: ASP.Net MVC Beta - ActionLink isn't generic anymore

Thanks--this post saved me too!
12/18/2008 9:52 AM | m
Gravatar

# re: ASP.Net MVC Beta - ActionLink isn't generic anymore

Thanks post saved me as well , it seems kind of obvious after reading this , i think they should have included a note in the release docs or some kind of reference to the download.
12/29/2008 12:22 AM | Jameel
Gravatar

# re: ASP.Net MVC Beta - ActionLink isn't generic anymore

Add another MVC.NU-B saved to your credit. Thanks much!
1/1/2009 11:03 PM | James Fleming
Gravatar

# re: ASP.Net MVC Beta - ActionLink isn't generic anymore

Hi Guys

I've downloaded ASP.NET MVC Beta Futures and add Microsoft.Web.Mvc.dll into the reference (I am testing the MvcContrib.Samples.HTMLHelper).

Add the <add namespace="Microsoft.Web.Mvc"/> into /configuration/system.web/pages/namespaces web.config.

When I ran it, I got the same error though:

Compiler Error Message: CS0411: The type arguments for method 'Microsoft.Web.Mvc.LinkExtensions.ActionLink<TController>(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression<System.Action<TController>>, string)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Any ideas?
1/3/2009 4:20 PM | dewacorp.alliances
Gravatar

# re: ASP.Net MVC Beta - ActionLink isn't generic anymore

Continuing as per above:

The error was on line 6:

The source error:

Line 4: <p>The UI Helpers sample application currently has three helpers:</p>
Line 5: <ul>
Line 6: <li><%= Html.ActionLink("Form Helper", "FormHelper") %></li>
Line 7: <li><%= Html.ActionLink("Validation Helper", "ValidationHelper") %></li>
Line 8: <li><%= Html.ActionLink("Grid", "Grid") %></li>
1/3/2009 4:22 PM | dewacorp.alliances
Gravatar

# re: ASP.Net MVC Beta - ActionLink isn't generic anymore

It is worth noting that the ASP.NET MVC Futures assembly is effectively a collection work-in-progress code which is not as rigorously tested as the core MVC assemblies.

In addition, there is a concern that using lambda expressions with ActionLink<T> may be quite a hit on performance as lambda's can be expensive to process. Large pages generating a good number of ActionLink<T>'s with lambdas may see quite a decline in rendering speed.

http://www.codeplex.com/aspnet/WorkItem/View.aspx?WorkItemId=907


2/3/2009 11:04 AM | Andy Gibson
Gravatar

# re: ASP.Net MVC Beta - ActionLink isn't generic anymore

I am using yonkly open source code to develop yonkly application locally.
So i am getting error with this code.
----------> Error occuring here <----------

i) <%=Html.ActionLink<ProfileController>(p => p.Edit(), "click here")%> in edit.aspx page

ii) (<%=Html.ActionLink<GroupController>(g => g.New(), "create group")%>) in List.aspx page

iii) <%= ViewData.Model.IsAuthenticated ? Html.ActionLink<GroupController>(g => g.New(), "create group") : "" %> in UserSidebar.aspx page

Error description:


Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 136: <h2>
Line 137: My Groups
Line 138: <%= ViewData.Model.IsAuthenticated ? Html.ActionLink<GroupController>(g => g.New(), "create group") : "" %>
Line 139: </h2>
Line 140: <%


Source File: d:\bharathsharma\yonkly\yonkly-18784\Yonkly\Views\Shared\UserSidebar.ascx Line: 138




Please help me... with neat description please
3/23/2009 9:19 AM | Bharath
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: